gpt4 book ai didi

jquery - 使用 jQuery 获取组合框的选定键/值

转载 作者:行者123 更新时间:2023-12-03 21:28:18 26 4
gpt4 key购买 nike

请问如何使用 jQuery 获取 HTML 选择组合框的选定键和值?

$(this).find("select").each(function () {
if ($.trim($(this).val()) != '') {
searchString += $.trim($(this).val()) + " "; //This gives me the key. How can I get the value also?
}
});

谢谢

最佳答案

我假设“键”和“值”你的意思是:

<select>
<option value="KEY">VALUE</option>
</select>

如果是这种情况,这将为您提供“VALUE”:

$(this).find('option:selected').text();

你可以这样获取“KEY”:

$(this).find('option:selected').val();

关于jquery - 使用 jQuery 获取组合框的选定键/值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5714196/

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