I have a dropdown menu and I want to disable/enable a button on my page when a certain value is selected. It works in all browsers but IE7 and below. Is there a work around?
Code:
<script type="text/javascript">
$(document).ready(function() {
//Start Buttons
$(".nextbutton").button({ disabled: true });
(".nextbutton").click(function() { $("#phonetypeform").submit() });
//Enable Next Step
$('.enablenext').click(function(){
$(".nextbutton").button("enable");
});
//Disable Next Step
$('.disablenext').click(function(){
$(".nextbutton").button("disable");
});
});
</script>
<form>
开发者_如何学运维 <select name="porting-p1"class="dropdown">
<option value="" class="disablenext">Please select an option...</option>
<option value="1" class="enablenext">I want to keep my current phone number</option>
<option value="2" class="enablenext">I want to choose a new number</option>
</select>
</form>
<button class="nextbutton">Next Step</button>
IE7 doesn't seem to like the click event on <option>
tags.
Here's a short demo that should work for you using the change()
event instead.
$(document).ready(function() {
$(".nextbutton").button({ disabled: true });
$('.dropdown').change(function() {
if ($('.dropdown').val() == 0) {
$(".nextbutton").button({ disabled: true });
} else {
$(".nextbutton").button({ disabled: false });
}
});
});
Have you tried
$(".nextbutton").attr("disabled", "disabled");
and
$(".nextbutton").removeAttr("disabled");
?
HTH
精彩评论