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
215 views
in Technique[技术] by (71.8m points)

javascript - jquery enable select only if certain options are selected

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

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

1 Reply

0 votes
by (71.8m points)

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!).


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

...