仅当选择某些选项时才启用jquery选择 [英] jquery enable select only if certain options are selected
问题描述
我有这种形式,从1开始选择DISABLED和4个选项,我需要一个jQuery这样做:
如果选项#1 (点击) 检查是否选择了其他选项并重置(擦除值和取消选中框)如果选项#2 (点击)激活选择菜单并检查是否选择了其他选项并进行复位(擦除值和取消选中框)如果选项#3 (点击),则检查是否为
其他选项被选中并且复位(擦除值和取消选中框)如果选项#4 (在键控上)激活选择菜单复位和禁用其他选项选项
<!DOCTYPE html>
< html>
< script type =text / javascript>
$(document).ready(function()
{
});
< / script>
< body>
< option value =>测试#1< / option>
< option value =>测试#2< / option>
< / select>
< div>
选项#1<输入名称=op1type =checkboxvalue =>
< / div>
< div>
选项#2<输入名称=op2type =checkboxvalue =>
< / div>
< div>
选项#3<输入名称=op3type =checkboxvalue =>
< / div>
< div>
选项#4<输入名称=type =text>
< / div>
< / body>
< / html>
更新的小提琴: < a href =http://jsfiddle.net/zZSJb/3/ =nofollow> http://jsfiddle.net/zZSJb/3/
类似这样的: http://jsfiddle.net/zZSJb /
$('#op1,#op3')。click(function(){
$('input'[type =checkbox]')。removeAttr('checked');
$(this).attr('checked',true);
});
$ b $('#op2')。click(function(){
$('#menus')。removeAttr('disabled');
$('input [ ('checked');
$(this).attr('checked',true);
});
$ b $('#txt')。keyup(function(){
$('#menus')。removeAttr('disabled');
$('input [ ('''');'
});
您可能需要根据您的确切需求进行微调(我无法完全弄清楚! )。
i have this form that starts with 1 select DISABLED and 4 options i need a jquery that does this:
if OPTION #1 (on click) check if other options are selected and RESET (erase values and uncheck boxes)
if OPTION #2 (on click) ACTIVATE select menu and check if other options are selected and RESET (erase values and uncheck boxes)
if OPTION #3 (on click) check if other options are selected and RESET (erase values and uncheck boxes)
if OPTION #4 (on keyup) ACTIVATE select menu RESET and DISABLE other options
<!DOCTYPE html>
<html>
<script type="text/javascript">
$(document).ready(function()
{
});
</script>
<body>
<select name="menus" id="menus" style="width:500px; height:200px" size="3" disabled="disabled">
<option value="">Test#1</option>
<option value="">Test#2</option>
</select>
<div>
Option #1 <input name="op1" type="checkbox" value="">
</div>
<div>
Option #2 <input name="op2" type="checkbox" value="">
</div>
<div>
Option #3 <input name="op3" type="checkbox" value="">
</div>
<div>
Option #4 <input name="" type="text">
</div>
</body>
</html>
Updated fiddle: http://jsfiddle.net/zZSJb/3/
Something like this: http://jsfiddle.net/zZSJb/
$('#op1, #op3').click(function() {
$('input[type="checkbox"]').removeAttr('checked');
$(this).attr('checked', true);
});
$('#op2').click(function() {
$('#menus').removeAttr('disabled');
$('input[type="checkbox"]').removeAttr('checked');
$(this).attr('checked', true);
});
$('#txt').keyup(function() {
$('#menus').removeAttr('disabled');
$('input[type="checkbox"]').removeAttr('checked').attr('disabled', true);
});
You may need to fine tune it to your exact needs (which I couldn't completely figure out!).
这篇关于仅当选择某些选项时才启用jquery选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!