当下拉列表选择为“是”或“否”时,我想要更新文本框。我检查的代码是Y或N的选项。如何检查选择了哪个值?
HTML
<select id="SelectionFlag" name="SelectionFlag">
<option value="">Select one</option>
<option selected="selected" value="Y">Yes</option>
<option value="N">No</option>
</select>
jquery的
$("#SelectionFlag").change(function () {
var currentYear = (new Date).getFullYear();
alert(currentYear + 1);
if ($("#SelectionFlag").value = "N") {
$("#TermDate").val("12/31/" + currentYear);
}
if($("#SelectionFlag").value = "Y")
{
$("#EffectiveDate").val("12/31/" + (currentYear + 1));
}
});
答案 0 :(得分:4)
将您的IF语句更改为:
if ($("#SelectionFlag").val() == "N")
和
if ($("#SelectionFlag").val() == "Y")
答案 1 :(得分:1)
$("#SelectionFlag").change(function() {
var currentYear = (new Date).getFullYear();
// alert(currentYear + 1);
if ($(this).val() == "N") {
$("#TermDate").val("12/31/" + currentYear);
} else if ($(this).val() == "Y") {
$("#EffectiveDate").val("12/31/" + (currentYear + 1));
}
});
答案 2 :(得分:0)
将$("#SelectionFlag").value
替换为$("#SelectionFlag").val()