2013-07-23 70 views
0

我在這裏有這個模板複選框。無論何時點擊,我都需要在我的jQuery中調用。我會如何做,我是新來的模板。jquery-template複選框oncheck

script id="listTemplate" type="text/x-jquery-template"> 
<div class="task_block clearfix modalRow"> 
<input type="checkbox" class="itemLinked" name="link" data-itemid="${ItemId}" data-itemtype="${ItemType}" data-linkid="${Id}" {{if IsLinked}}checked="checked"{{/if}}> 
<div class="left mls"> 

這是我在我的jQuery中。

$(document).ready(function() { 
    $("input[name=link]").change(function() { 
     alert("test"); 
    }); 

}); 
+0

從DOC:_「值:。一個屬性值可以是一個不帶引號的單詞或引用字符串」 _ –

+0

嘗試使用'on()'代替:'$(document).on('change','input [name =「link」]',function(){...});' –

+0

我試過了一個第一,但是像這樣$(「input [name = link]」。on(「change」,function(){並且這兩種方式似乎都不能正常工作.. –

回答

0

在之前的jQuery 1.7版本可以使用live()附加一個事件來動態地添加元素。

例如:

$('input[name=link]').live('change', function() { 
    alert('test'); 
}); 

看到一個工作示例:http://jsfiddle.net/coderdude/GyCCF/