开发者

Problem when setting a value to a dropdown in jQuery

开发者 https://www.devze.com 2023-03-12 04:15 出处:网络
I have this strange problem in JQuery. I try to set a value to a dropdown dinamically, so I have this code:

I have this strange problem in JQuery. I try to set a value to a dropdown dinamically, so I have this code:

$('#activity').val(idValue);
//or this way:
$('#activity').val("'"+idValue+"'");

but it does not work. However, if I'm setting the value "statically" then it works:

$('#activity').val('23');

So, why does not accept the value from the variable? Or what am I doing wrong? Thanks!

UPDATE

I have tried the code in jsfiddle and it does work. It seems that the problem was related to the JSON data i was parsing. Thanks for the help!开发者_如何学编程


What do you get if you alert idValue?

Alternatively, I would also try attr().

$('#activity').attr('value',idValue);


idValue may be a number type, try

$('#activity').val(idValue.toString());
0

精彩评论

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