Selecting selectbox options by array values
I am getting some values via json type ajax request with Jquery. When I use alert(msg.options)
it alerts ["1","3","8"]
If I use below script to select needed options, it works. It selects only options that have value 1 and 3 and 8 :
$('#input_6').val([开发者_如何转开发"1","3","8"]);
But below script doesn't work even if it alerts the same:
$('#input_6').val(msg.options);
How can I fix this? Thank you...
Try:
$('#input_6').val($.parseJSON(msg.options));
$(document).ready(function () {
var msg = {};
msg.options = '["1","3","8"]'
$('#input_6').val( eval( msg.options ) );
});
http://jsfiddle.net/yjHUS/2/
精彩评论