我有一个 HTML 订阅表单,它使用(或应该使用)一个 jquery 代码来灰显提交按钮,直到字段名称被填写。
但是,它不起作用...
有什么问题的线索吗?这是代码:
<head>
<script type="text/javascript">
var $submit = $("input[type=submit]");
if ( $(".subName").length > 0 ) {
$submit.attr("disabled","disabled");
} else {
$submit.removeAttr("disabled");
}
</script>
</head>
<body>
<form action="" method="post" id="subscribe" name="subscribe">
<input type="hidden" name="action" value="subscribe">
<label>NAME:</label>
<input type="text" name="name" class="subName" id="sub_first_name">
<label>EMAIL:</label>
<input type="text" name="email" class="subEmail" id="sub_email">
<input type="submit" name="button" value="Subscribe" />
</form>
</body>
谢谢!
- - - - - - - - - - - - - 编辑
<form action="" method="post" id="subscribe" name="subscribe">
<label>NAME:</label>
<input type="text" name="name" class="subName" id="sub_first_name">
<label>EMAIL:</label>
<input type="text" name="email" class="subEmail" id="sub_email">
<input type="submit" name="button" value="Subscribe" />
</form>
JS:
<script type="text/javascript">
$(document).ready(function() {
var $submit = $("input[type=submit]");
$('.subName').on('change', function() {
if ( ! $(".subName").val().length ) {
$submit.attr("disabled","disabled");
} else {
$submit.removeAttr("disabled");
}
});
}
</script>
但仍然无法正常工作:(