开发者

jquery conversion for this javascript

I have the following code:

for (i=1; i<=len; i++) {
        var optcheck = col+'|'+document.getElementById('color').options[i].value;
        text = document.getElementById('color').options[i].text.split(' - ');
}

This is part of the original code from javascript. I have successfully converted much of the other stuff into jquery but I can't seem to figure out how to convert this into jquery.

Please note that col is just value I am passing when calling the funct开发者_如何学Goion which is usually "16"

Here is what I got so far:

    for (i=1; i<=len; i++) {
        var optcheck = col+'|'+$('#color').val(i);
        text = $('#color').val(i).text.split(' - ');
      }

Also, the original code works fine in Chrome, Firefox, Opera and Safari but in IE (all version from 6 to 9) I get an error saying 'options[...].value' is not null or not an object

Thanks for the help!


You're mis-calling val.

Change it to $('#color option').eq(i).text() and $('#color option').eq(i).val()


$('#color option').each(function() {
    var a = col + '|' + this.value,
        b = this.text.split(' - ');

    // do stuff with a and b
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜