gpt4 book ai didi

php - jQuery 获取特定选项标签选择的值

转载 作者:行者123 更新时间:2023-11-30 13:08:05 25 4
gpt4 key购买 nike

我有这个,

<select id="customUser_id" name="customUser_id">
<option value="2" label="Friends Of Friends">Friends Of Friends</option>
<option selected="selected" value="3" label="Friends Only">Friends Only</option>
<option value="4" label="Specific People">Specific People</option>
<option value="0" label="Only Me">Only Me</option>
</select>

我想使用 jQuery 获取 Selected Option 的值。

目前我正在使用这样的 onchange() 事件,

$('#customUser_id').change(function(){
if(($(this).val()==2)){
$("#customWallPost3").text("Only Friends of Friends can see this");
}
else if(($(this).val()==3)){
$("#customWallPost3").text("Only Friends can see this");
}
else if(($(this).val()==4)){
$("#customWallPost3").text("Only the people above can see this");
}
else if(($(this).val()==0)){
$("#customWallPost3").text("Only I can see this");
}
else{
$("#customWallPost3").text("");
}
});

这仅在更改选项值时有效,但我也想以此获取选定的选项值。提前致谢

最佳答案

不确定你要的是什么......

I also want to get selected option value with this..

但要获取选定的选项值,您可以使用

  $('#customUser_id').val();

这为您提供了 <select> 的选定值ID 为 customUser_id

已更新

如果你想获取选中选项的文本,那么你可以这样做

 $("#customUser_id option:selected").text();

关于php - jQuery 获取特定选项标签选择的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14930610/

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