我的 JQ 脚本有问题,我找不到错误。当我从选择框中选择是选项时,网站应显示“键入您的电子邮件地址”并隐藏“键入您的新用户名”。这是代码:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"> </script>
<script>
$(function () {
$('#am').on('change', function () {
var stringt = $('#am :selected').val();
if (stringt === "Yes") {
$("#campos1").hide();
$("#campos2").show();
} else {
$("#campos1").show();
$("#campos2").hide();
}
});
});
</script>
</head>
<html>
<li>Are you already a member?
<select name="am">
<option value="1" selected="selected">Yes</option>
<option value="2">No</option>
</select>
</li>
<div id="campos1">
<li>Type you email address.
<input id="Field5" name="institucion_1" type="text" />
</li>
</div>
<div id="campos2">
<li>Type a new username.
<input type="text" />
</li>
</div>
</html>
这是 jSfiddle: http: //jsfiddle.net/sushanth009/CcCbQ/5/ 随时修改并向我提出任何意见。:)