我想更改元素所需的信息,但我不知道为什么我的脚本不起作用! src是否正确?我的脚本不起作用
<head>
<script src="/Scripts/jquery-1.10.2.js"></script>
<script src="/Scripts/jquery-1.10.2.min.js"></script>
<script>
$('#form1 input[type=text]').on('change invalid', function() {
var textfield = $(this).get(0);
// 'setCustomValidity not only sets the message, but also marks
// the field as invalid. In order to see whether the field really is
// invalid, we have to remove the message first
textfield.setCustomValidity('');
if (!textfield.validity.valid) {
textfield.setCustomValidity('Some message... ');
}
});
</script>
这里是身体。
<form id="form1" class="form-basic" action="~/MortgageAndRent/InsertMortgageAndRent/" method="post" >
<input type="hidden" name="UserId" value="@Model.UserId" />
<div class="form-row">
<label>
<span>Province</span>
<input type="text" name="AddressViewModel.Province" value="@Model.AddressViewModel.Province" required />
</label>
</div>
<div class="form-row">
<label>
<span>City</span>
<input type="text" name="AddressViewModel.City" value="@Model.AddressViewModel.City" required />
</label>
</div>
。 。 。
你必须先学习如何调试你的代码。检查此链接http://stackoverflow.com/questions/988363/how-can-i-debug-my-javascript-code –
你的'#form2 input [type = text]'元素在你运行时不存在你的代码设置事件处理程序。查看链接问题的答案。 (你还需要在输入周围使用'id =“form2”'或者改变选择器的元素。) –