gpt4 book ai didi

javascript - 禁用选项选择按钮

转载 作者:行者123 更新时间:2023-12-01 04:00:43 25 4
gpt4 key购买 nike

您好,我想在选择选项是特定属性时禁用按钮。

我的代码是这样的:

<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>

如果期权值(value)是Dove Sei?我想禁用该按钮。我可以尝试这段代码,但不要运行。

你能帮我吗?

最佳答案

  1. 您的 $("company") 选择器不匹配任何内容,如果您想按 ID 选择,您应该使用 $("#company")
  2. 请检查:How do I get the text value of a selected option?,而不是 $(this).find(':value').text() - 由于您还设置了 value 属性,因此您可以简单地使用 $(this).val()
  3. 您有两个具有相同 ID 的按钮,请记住,操作处理程序中的 $("#buttonSurvey") 选择器将始终且仅选择第一个按钮。

关于javascript - 禁用选项选择按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42207125/

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