0

一直在尝试解决这个问题,但没有运气。

jQuery("#choosenCause option:selected").removeAttr("selected","selected");

jQuery('#choosenCause option[value="'+json.causeID+'"]').attr("selected",true);

我正在使用上述内容,它添加selected="selected"到正确的元素,但不会更改用户看到的选定元素。

完整的 JS 在这里 - http://inspire.simplyfundraising.co.uk/wp-content/themes/inspire/assets/js/promojs.js

4

2 回答 2

4

要设置select元素的选定选项,请使用val()

jQuery('#choosenCause').val(json.causeID);
于 2012-05-29T13:10:36.540 回答
0

在第一个字符串中,您需要更正代码 -jQuery("#choosenCause option:selected").removeAttr("selected"); 第二个字符串工作正常,如我所见

于 2012-05-29T13:13:46.227 回答