[問題] 初學JavaScript (已學過PHP)

看板Ajax作者時間12年前 (2013/07/14 23:18), 編輯推噓3(3011)
留言14則, 5人參與, 最新討論串1/1
各位大大好,小弟寫PHP 今天開始想碰一些Javascript的東西,但完全沒有概念和基礎 爬了一些文 想試著寫些簡單的東西就馬上遇到問題,手邊也沒有工具書可參考 故請教版上高手們..... 我抄寫了一個按鈕的程式,按了之後會show出Hello 的字樣 但只會出現按鈕,按了之後不會有字樣(檔案存成HTML 用notepad++寫的) 程式碼如下... <html> <head> <title>jQuery Tutorial 1</title> <script type="text/javascript" src="jquery.min.js"></script> <script type="text/javascript"> function showMsg() { $('#msg').html('<h1>Hello</h1>'); } </script> </head> <body> <div id="msg"></div> <input type="button" value="Click Me" onclick="showMsg()" /> </body> </html> 檔案放在appserv的www根目錄資料夾,另外我有下載jquery-1.2.1.min 下載之後不知道要放在哪...@@a 很抱歉問愚蠢問題 但還請各位能幫幫我>< -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.166.161.21

07/14 23:22, , 1F
src="jquery.min.js" 改成 jquery-1.2.1.min 看看
07/14 23:22, 1F

07/14 23:24, , 2F
jquery-1.2.1.min 跟你的PHP檔 放在同一個目錄
07/14 23:24, 2F

07/14 23:25, , 3F
天阿真是感謝您~~~~~
07/14 23:25, 3F

07/14 23:30, , 4F
src = source 可以寫相對路徑或絕對路徑
07/14 23:30, 4F

07/14 23:30, , 5F
初學最好學好一點的做法 不要用on click
07/14 23:30, 5F

07/14 23:32, , 6F
P.S jquery現在已經出到v1.10.3囉
07/14 23:32, 6F

07/14 23:32, , 7F
給 button 一個 id 用$(button_id).on('click', showIng)
07/14 23:32, 7F

07/14 23:33, , 8F
哇咧 手機又自動亂訂正了 是showMsg
07/14 23:33, 8F

07/14 23:42, , 9F
s25g5d4大寫的我還看不懂XD cold514大感謝您~
07/14 23:42, 9F

07/15 07:57, , 10F
dynamic binding event
07/15 07:57, 10F

07/19 03:35, , 11F
<input type="button" id="btnShowMsg" value="Click Me"/>
07/19 03:35, 11F

07/19 03:36, , 12F
<script> $("#btnShowMsg").click(function () {
07/19 03:36, 12F

07/19 03:37, , 13F
$('#msg').html('<h1>Hello</h1>');
07/19 03:37, 13F

07/19 03:37, , 14F
} </script>
07/19 03:37, 14F
文章代碼(AID): #1Hui4y3L (Ajax)
文章代碼(AID): #1Hui4y3L (Ajax)