簡體   English   中英

JQuery live不起作用

[英]JQuery live doesn't work

當有一個密鑰時,我試着將.live內容放入div ...我在這里查看了forumtopic但是我沒有找到答案......

為什么我的代碼不起作用? 我用這個JQuery:

<script type="text/javascript" src="jquery-ui-1.7.1.custom.min.js"></script> 


<script type="text/javascript">

$(document).ready(function() {
// When the document is ready set up our sortable with it's inherant function(s)

  $(".atleetnaamlink").live('keyup', function(){
    alert('test');
  });  
</script>

嘗試on

$(selector).live(events, data, handler);                // jQuery 1.3+
$(document).delegate(selector, events, data, handler);  // jQuery 1.4.3+
$(document).on(events, selector, data, handler);        // jQuery 1.7+

$(document).ready(function() {
 $("body").on('keyup' ,'.atleetnaamlink', function(){
   alert('test');
 });  
});

DEMO

.live()已棄用。 請改用.on() 那可行。

$(".atleetnaamlink").on('keyup', function(){
    alert('test');
}); 

你錯過了}); 工作演示 http://jsfiddle.net/JwRRH/

希望它有所幫助:)順便說一下live是不贊成的,如果你熱衷於檢查這個jQuery live方法有什么問題?

  $(document).ready(function() {
    // When the document is ready set up our sortable with it's inherant function(s)

      $(".atleetnaamlink").live('keyup', function(){
        alert('test');
      });  
    });​

要么*

 $(document).ready(function() {
        // When the document is ready set up our sortable with it's inherant function(s)

          $(document).live('keyup',".atleetnaamlink", function(){
            alert('test');
          });  
        });​

添加以上內容:

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> 
<script type="text/javascript" src="jquery-ui-1.7.1.custom.min.js"></script> 

看看這是否有效

重要的是不要忘記接受它,如果它解決了你的問題。

暫無
暫無

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

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