<script type='text/javascript' href='jquery.js'></script>
<script>
$(document).ready(function(){
$('.selects').change(function(){
$('.select').
})
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!doctype HTML>
<input type='radio' id ='index1' value='1' name='radio1' disabled>radio button 1</input><br><br>
<select class='select' data-value='1'>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
</select><br><br>
<input type='radio' id ='index2' value='2' name='radio2' disabled>radio button 2</input><br><br>
<select class='select' data-value='2'>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
</select><br><br>
如果选择菜单更改,如何从单选按钮中删除已禁用的属性?
<!doctype HTML>
<?php
$x = 1;
$y = 1;
while($x <= 2){
echo "<input type='radio' id ='index$x' value='$x' name='radio$x' disabled>radio button $x</input><br><br>";
echo "<select class='select' data-value='$x'>";
while($y<= 4){
echo "<option>$y</option>";
$y++;
}
echo "</select><br><br>";
$x++;
$y = 1;
}
?>
<script type='text/javascript' href='jquery-2.1.4.min.js'></script>
<script>
$(document).ready(function(){
$('.select').change(function(){
var sel = $(this).attr('data-value');
var selVal = $(this).val();
if(selVal >= 3){
$('#index'+sel).prop('disabled', false);
}
});
});
</script>
当选择菜单选项值达到3或更高值时,单选按钮的禁用属性将更改为false.我也尝试过以下脚本:
<script>
$(document).ready(function(){
$('.select').change(function(){
var sel = $(this).attr('data-value');
if($( ".select option:selected" ) >= 3){
$('#index'+sel).prop('disabled', false);
}
});
});
</script>
我在href =’jquery-2.1.4.min / js’的代码中看到了一个打字错误.我尝试替换它但仍然无效.我收到一个控制台错误未捕获的ReferenceError:$未在第6行中定义,即$(document).ready(function(){
编辑:提供Stack片段转换为html
最佳答案 prop(‘disabled’)可以采用布尔表达式导致true或false,这将禁用或启用控件.
$(document).ready(function() {
$('.select').change(function() {
var sel = $(this).attr('data-value');
var selVal = $(this).val();
$('#index' + sel).prop('disabled', selVal < 3);
});
});
JSFiddle:https://jsfiddle.net/TrueBlueAussie/wnLfxhLo/1/
注意:由于应禁用默认条目的无线电状态,因此需要触发初始更改事件:
$(document).ready(function() {
$('.select').change(function() {
var sel = $(this).attr('data-value');
var selVal = $(this).val();
$('#index' + sel).prop('disabled', selVal < 3);
}).change();
});