如何使用
jquery正确禁用和启用表单元素.当我点击选择时,我需要禁用文本表单元素.反之亦然.
<html> <head> <script src="jq.js"></script> <script> $(function(){ $('#fromdate').click(function(){ $('#yosh').attr('disabled','disabled'); $('#fromdate').removeAttr('disabled'); }); $('#yosh').click(function(){ $('#yosh').removeAttr('disabled'); $('#fromdate').attr('disabled','disabled'); }); }); </script> </head> <body> Sort by: <select name="yosh" id="yosh"> <option value="daily">daily</option> <option value="weekly">yesterday</option> <option value="weekly">weekly</option> <option value="monthly">monthly</option> <option value="yearly">yearly</option> </select><br/> date range:<br/> From:<input type="text" value="" name="fromdate" id="fromdate"></input><br/> To:<input type="text" value="" name="todate" id="todate"></input><br/> Customer:<input type="text" value="" name="customer" id="customer"></input> </body> </html>
解决方法
我在评论中写的例子:
<span id="spnSel"> <select name="yosh" id="yosh"> <option value="daily">daily</option> <option value="weekly">yesterday</option> <option value="weekly">weekly</option> <option value="monthly">monthly</option> <option value="yearly">yearly</option> </select> </span>
添加此事件:
$('#spnSel').mouSEOver(function () { $('#yosh').prop('disabled',false); });