我有这段代码......
function roundtrip() {
//alert("Round Trip");
$("#checkoutdate").prop("disabled", false);
$("#btncheckoutdate").show();
}
function onewaytrip() {
//alert("One Way Trip");
$("#checkoutdate").prop("disabled", true);
$("#btncheckoutdate").hide();
}
n html代码是
<input type="radio" name="trip_type" id="trip_type" onclick = "return onewaytrip()" value="One_way"> One Way Trip
<input type="radio" name="trip_type" id="trip_type" onclick = "return roundtrip()" checked="checked" value="round_trip"> Round Trip
<label name="depaturedate">Departure Date</label>
<input id="checkindate" class="font11textbox" type="text" readonly="readonly" style="position: relative;" autocomplete="off" maxlength="12" name="checkindate">
<img id="btncheckindate" border="0" name="btncheckindate" alt="select date" src="images/calendar1.gif">
<label name="returndate">Return</label>
<input id="checkoutdate" class="font11textbox" type="text" readonly="readonly" style="position: relative;" autocomplete="off" maxlength="12" name="checkoutdate">
<img id="btncheckoutdate" border="0" name="btncheckoutdate" alt="select date" src="images/calendar1.gif">
</br>
目的是隐藏/显示日历图像n,点击相应的单选按钮启用/禁用输入框。
但我收到以下错误
Uncaught TypeError: Cannot call method 'prop' of null.
它真的很困扰我。代码对于错误来说非常简单。我需要总结帮助。
答案 0 :(得分:2)
如何使用正确的事件处理程序:
<input type="radio" name="trip_type" id="oneway" value="One_way"> One Way Trip
<input type="radio" name="trip_type" id="roundtrip" value="round_trip" checked> Round Trip
JS
jQuery(function($) {
$('[name="trip_type"]').on('change', function() {
state = this.checked && this.id == 'oneway';
$("#checkoutdate").prop("disabled", state);
$("#btncheckoutdate").toggle(state);
});
});