text
Then in **javascript** with a conditon like this:
$("#swas"+key).removeClass('colorme');
function xx(key, arr) {
for (var v in arr) { //LOOP
var k = arr[v];
if ($("#swas" + k) != key) {
$("#swas" + k).addClass('colorme');
}
}
}
What have I done wrong ?
**UPDATE**
The reason I want to mix "swas" with array because in php page there´re alot of div that name
swas1, swas2, swas3, swas4.........>etc
And "key" is the id of current div that will be clicked. and "key" value : 001, 002, 003, 004 etc
What I want to do is to make the other div (that´s not the current div )to not change color.
that´s why I have to mix the word "swas" with the "key" in javascript.
**UPDATE2**
Now It work with script above but new probelm, it not remove the class when clicked :S
**UPDATE3**
Now everything just work fine after I move the $("#swas"+key).removeClass('colorme');
To the bottom :) S以上就是Stmixing string with array variable to assign an id for an element in javascript的详细内容,更多请关注web前端其它相关文章!
未经允许不得转载:web前端首页 » JavaScript 答疑