Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
208 views
in Technique[技术] by (71.8m points)

javascript - Disable button from option select

Hello i want to disable button when a select option is a specific attribute.

My code is this:

<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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  1. Your $("company") selector does not match anything, if you want to select by id, you should have used $("#company").
  2. Instead of $(this).find(':value').text(), please check: How do I get the text value of a selected option? - Since you also set the value property, you could simply use $(this).val()
  3. 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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...