开发者

Correct Syntax to Include object data in jquery selector

I'm trying to make a jquery selector as per the below code. However, my js is pretty poor and i开发者_JS百科'm not sure what the correct syntax is to use data.key as the value here (data.key should have a numeric value btw). I'd know how to do this in php! But not sure here :(

onClick: function(data) {
    if($(".myForm select option[value=data.key]").is(':selected')){
        alert('foo');
    }
}

Any advice would be very gratefully received!

Thanks!


It is just a string. Use the + operator.

".myForm select option[value=" + data.key + "]")
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜