作者painterfun (平安是福)
看板Ajax
標題[問題] jquery提問
時間Wed Dec 18 19:54:26 2013
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
.help {display: none}
#menu {display: none}
</style>
<script src="
http://code.jquery.com/jquery-latest.min.js"></script>
<script>
$("form").submit(function() {
if ($("input
#username").val() == "")
$("span.help").show();
return false;
});
</script>
</head>
<body>
<form method="post">
<label for="username">請輸入大名</label>
<input type="text" id="username" name="username" />
<span class="help">這個欄位必填喔</span>
<input type="submit"/>
</form>
</body>
</html>
網路上找的資料驗證範例
但沒有預期的效果
請板上高手指點一下
另外請教瀏覽器要怎麼debug呢
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.57.123.247
1F:推 duck10704:你的預期效果是help那邊原本是要隱藏的吧? 12/18 22:48
2F:推 mmis1000:css缺了分號 12/18 22:50
3F:→ mmis1000:下次遇到問題先用瀏覽器的開發者工具,還是不行在發問吧 12/18 22:52
4F:→ painterfun:謝謝各位 12/19 00:49
5F:→ painterfun:結果問題是出在if要用{}包起條件式 還有jquery執行時 12/19 00:55
6F:→ painterfun:form沒辦法被抓到 把script移到最下方就好了 12/19 00:56
7F:→ painterfun:或許ready事件也可以解決(? 12/19 00:57
8F:→ painterfun:再次感謝各位的相助 12/19 00:59