[英]How To Select A Certain Option Field
Jquery is not my main language PHP is. Jquery 不是我的主要语言 PHP 是。
Anyway,反正,
What I am trying to do is detect if a field has been selected my code almost works but the issue is that when it selects the certain option I get a alert which is good but then when I select the dropdown again [since its being selected] I get another alert which I don't want.我想要做的是检测是否选择了一个字段,我的代码几乎可以工作,但问题是当它选择某个选项时,我会收到一个很好的警报,但是当我 select 再次下拉[因为它被选中]我收到另一个我不想要的警报。 What I do want is once the user select the dropdown then clicks the option again I want another alert我想要的是一旦用户 select 下拉菜单然后再次单击该选项我想要另一个警报
$('#_privacy_selection').click(function() {
if($("#_privacy_selection option:selected").text() == 'Certain Users'){
alert(9);
return false;
}
});
Thanks谢谢
Instead of click
function use change
function on <option>
It will be fired only when you change selected option.而不是click
function 使用change
function on <option>
只有当您更改所选选项时才会触发。
$('#_privacy_selection').change(function() {
if($("#_privacy_selection option:selected").text() == 'Certain Users'){
alert(9);
return false;
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.