从选项选择中禁用按钮 [英] Disable button from option select
本文介绍了从选项选择中禁用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我想禁止按钮时,选择选项是一个特定的属性.
Hello i want to disable button when a select option is a specific attribute.
我的代码是这样的:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$("company").on('change',function(){
if($(this).find(':value').text()=="Dove Sei?")
$("#buttonSurvey").attr('disabled',true)
else
$("#buttonSurvey").attr('disabled',false)
});
</script>
<select class="selectpicker" data-live-search="true" id="company" data-size="5" title="Dove Sei?" data-width="100%">
<option data-tokens="Dove sei?" value="Dove Sei?" id="Dove Sei?" selected>Dove sei?</option>
<option data-tokens="another" id="another" value="another" data-picture="another.png">another</option>
<option data-tokens="another" id="another" value="another" data-picture="another.png">another</option>
<option data-tokens="another" id="another" value="another" data-picture="another.png">another</option>
</select>
<ul class="list-group" style="text-align: center;">
<li class="list-group-item" style="border-style: none;"><h4>Servizio</h4>
<div class="btn-group">
<button id="buttonSurvey" type="submit" class="btn btn-default" data-toggle="modal" data-target="#voteReg" name="survey1" value="green" onclick="getVote(this.value)" style="border: none;"><img src="Q1.png}" class="Vote"></button>
<button id="buttonSurvey" type="submit" class="btn btn-default" data-toggle="modal" data-target="#voteReg" name="survey1" value="green" onclick="getVote(this.value)" style="border: none;"><img src="Q2.png}" class="Vote"></button>
</div></li>
如果选项值为Dove Sei?我想禁用该按钮.我可以尝试这段代码,但是不能运行.
If option value is Dove Sei? i want disable the button. I can try this code but don't run.
你能帮我吗?
推荐答案
- 您的
$("company")
选择器不匹配任何内容,如果要按ID选择,则应使用$("#company")
. - 而不是
$(this).find(':value').text()
,请检查:选择器将始终且仅选择第一个.
- Your
$("company")
selector does not match anything, if you want to select by id, you should have used$("#company")
. - Instead of
$(this).find(':value').text()
, please check: How do I get the text value of a selected option? - Since you also set thevalue
property, you could simply use$(this).val()
- You have two buttons with the same id, keep in mind that the
$("#buttonSurvey")
selector in your action handler will always and only select the first one.
这篇关于从选项选择中禁用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文