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 + "]")
精彩评论