0
需要幫助來修復簡單的JQuery函數。以下代碼預計會顯示警報,但在任何時候都不會輸出。我是新來的這個東西。所以,如果出現問題,請糾正我。簡單的JQuery代碼 - 邏輯正確但警報不彈出
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
$('#check').click(function() {
if ($('#city').val() == '')
{
alert('Empty!!!');
}
else
{
alert('Contains: ' + $('#city').val());
}
});
</script>
</head>
<body>
<h3>Registration form</h3>
<form name="form1" method="post" action="">
City: <input type="text" name="city" id="city"><br>
Last name: <input type="text" name="LastName" value="Mouse"><br>
Phone number: <input type="text" name="Last" value="Mouse"><br>
<button id="check">Check</button>
</form>
你需要用在文件準備處理您的代碼 - '$(文件)。就緒(函數(){...'或'$(函數(){...' – 2014-09-05 13:16:46
Jay的權利,解釋:腳本在HTML輸出之前,因此在運行時#check元素不存在, – Paul 2014-09-05 13:17:53
這是不公平的標記重複,給出參考不同於我問。如果@Frederic可以恢復,因爲我是新手。 – 2014-09-05 14:42:10