gpt4 book ai didi

javascript - 如何使用jquery更改选择框中呈现的选定选项

转载 作者:行者123 更新时间:2023-11-28 04:25:16 25 4
gpt4 key购买 nike

我尝试了很多方法来使用 jquery 选择一个选项,包括 .val("0") .attr('selected', 'selected').attr('selected', 'true')TexoTela plugin .他们似乎都更新了 html,但浏览器仍然显示用户选择的最后一个项目。

试用 this fiddle ... 选择下拉值 1,然后单击链接。

有什么方法可以实际更新显示的值吗?

最佳答案

您的意思是更改选中的项目?

$('select').val('0');

还有其他方法,但这是基本的,以您为例。

jsfiddle

您可以阅读 .val() 的文档 here ,以及片段:

checks, or selects, all the radio buttons, checkboxes, and select options that match the set of values.

为 jQuery Mobile 编辑

对于 jQuery Mobile,您还需要按照 mobile docs 中所述刷新选择:

If you manipulate a select via JavaScript, you must call the refresh method on it to update the visual styling.

您可以通过以下方式做到这一点:

$('select').selectmenu("refresh",true);

关于javascript - 如何使用jquery更改选择框中呈现的选定选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6222559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com