簡體   English   中英

jQuery監聽器點擊不起作用

[英]jQuery listener click not working

所以我有這個代碼, 應該聽#button的點擊,但它不會工作,並讓我瘋了!

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
    $('#button').click(function() {
        alert('OK!');
    });
</script>

和HTML:

<input id="button" type="button" value="OK" />

這很奇怪。 歡迎任何幫助!

在document.ready函數中編寫代碼

<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js">
</script> 
<script type="text/javascript">
$(document).ready(function() {
    $('#button').click(function() {
        alert('OK!');
    });
});
</script>


 OR
<script type="text/javascript">
    function on_click() {
          alert("OK !!");
    }
    $(document).ready(function() { 
         $("#button").click(on_click);
    });
</script>

希望你從中得到一些想法

這是代碼應該是什么樣子:

<script type="text/javascript"
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js">
</script> 
<script type="text/javascript"> 
    // Now that jquery is include, place the code to wire up the button here
    $(function(){
        // Once the document.onload event fires, attach the click
        // event handler for the button
        $('#button').click(function() { 
            alert('OK!'); 
        });
    });
</script> 
<input id="button" type="button" value="OK" /> 

這是與此相關的jquery文檔: http//docs.jquery.com/How_jQuery_Works

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM