我有一个选择列表,并且基于该列表,除非选择了有效选项,否则我将按钮禁用,这可以正常工作,但是如果我按表单中的“重置”按钮,“提交”按钮将被启用,但仍应禁用(因为第一个选项的值为“”)。
我该如何补救?
谢谢
jQuery:
if ($("li#modFilterField_34 select").val() == "") {
$('.search input[type="submit"]').attr('disabled','disabled');
}
$("li#modFilterField_34 select").change(function(){
if ($(this).val() == "Paintings" ) {
$('.search input[type="submit"]').removeAttr('disabled');
} else if ($(this).val() == "Houses" ) {
$('.search input[type="submit"]').removeAttr('disabled');
} else {
$('.search input[type="submit"]').attr('disabled','disabled');
}
});
html:
<form id="modMtFilterForm0" name="modMtFilterForm0" method="get" action="/oljadir/index.php">
<ul class="modMtFilter" id="modMtFilter0">
<li class="mfieldtype_selectlist" id="modFilterField_34">
<label>Choose type*:</label>
<span class="filterinput"><select class="inputbox text_area" name="cf34">
<option value=""> </option>
<option value="Paintings">Paintings</option>
<option value="Houses">Houses</option>
</select>
</span></li>
<li class="mfieldtype_corename" id="modFilterField_1"><label>Name:</label><span class="filterinput"><input type="text" size="50" id="filter_cf1" name="link_name" class="inputbox text_area"></span></li><li class="mfieldtype_mcheckbox" id="modFilterField_33"><label>Ostalo::</label><span class="filterinput"><ul style="margin:0;padding:0;list-style-type:none"><li><input type="checkbox" id="filter_cf33_0" value="KTV" name="cf33[]"><label for="filter_cf33_0">KTV</label></li><li><input type="checkbox" id="filter_cf33_1" value="Internet" name="cf33[]"><label for="filter_cf33_1">Internet</label></li><li><input type="checkbox" id="filter_cf33_2" value="Prevoz" name="cf33[]"><label for="filter_cf33_2">Prevoz</label></li></ul></span></li> <li class="button-send"><input type="submit" onclick="javascript:var cookie = document.cookie.split(';');for(var i=0;i < cookie.length;i++) {var c = cookie[i];while (c.charAt(0)==' '){c = c.substring(1,c.length);}var name = c.split('=')[0];if( name.substr(0,35) == 'com_mtree_mfields_searchFieldValue_'){document.cookie = name + '=;';}}" value="Search" disabled="disabled"></li>
<button type="reset">Reset</button>
</ul>
</form>