[問題] jquery提問

看板Ajax作者 (平安是福)時間11年前 (2013/12/18 19:54), 編輯推噓2(206)
留言8則, 3人參與, 最新討論串1/1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "" rel="nofollow">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="" rel="nofollow">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="" rel="nofollow">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

12/18 22:48, , 1F
你的預期效果是help那邊原本是要隱藏的吧?
12/18 22:48, 1F

12/18 22:50, , 2F
css缺了分號
12/18 22:50, 2F

12/18 22:52, , 3F
下次遇到問題先用瀏覽器的開發者工具,還是不行在發問吧
12/18 22:52, 3F

12/19 00:49, , 4F
謝謝各位
12/19 00:49, 4F

12/19 00:55, , 5F
結果問題是出在if要用{}包起條件式 還有jquery執行時
12/19 00:55, 5F

12/19 00:56, , 6F
form沒辦法被抓到 把script移到最下方就好了
12/19 00:56, 6F

12/19 00:57, , 7F
或許ready事件也可以解決(?
12/19 00:57, 7F

12/19 00:59, , 8F
再次感謝各位的相助
12/19 00:59, 8F
文章代碼(AID): #1IiOpwc1 (Ajax)
文章代碼(AID): #1IiOpwc1 (Ajax)