请问如何使用 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/