-2
我想檢查輸入是否爲空與jQuery和代碼不起作用。檢查空輸入不工作
這是代碼:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="demo.js"></script>
</head>
<body>
<form>
<input type="text" id="name">
<input type="submit" id="btnConnect">
</form>
</body>
</html>
$('#btnConnect').click(function()
{
if($('#name').val() == '')
{
alert('Input is empty!');
}
});
檢查undefined – Geeky
當我運行你的代碼時,我得到一個警告「輸入是空的」,沒有填寫輸入。 –
將代碼包裝在$(document).ready(function(){})中;它的工作原理是 – Geeky