English 中文(简体)
jquery模板发动机,如何约束活动
原标题:jquery template engine, how to bind events

Is there any way to pass function to bind into jQuery template engine? http://api.jquery.com/tmpl/

如果我没有模板就建立超文本,我就这样做:

jQuery("<a>link</a>").click(function(){alert( hi! )}).appendTo( "#forms_container" );

如何用j Query模板做到这一点?

------------EDIT I found some library here http://knockoutjs.com/documentation/template-binding.html

并且似乎像j Query.live()这样的东西。

是否有其他有约束力的职能模板,或者这种方式主要被用作违约?

-----------EDIT Ok, then let it be .delegate. I think for my small task it will be enough, without adding more complexity with Knockout

最佳回答

与Ian s相似,但执行方面有差别:

jQuery( #forms_container ).delegate( a ,  click , function() {
   //Click event, with context (faster)
});

这意味着,表格中的所有链接——集装箱都将有这种点击事件,不管变化如何。 这与Ian s(适当合法)使用live<>code”的情况不同,因为它有某种背景,因此事件无需一切照旧。 如果你给出情况,则你可以使用<代码>live(如1.4),但我更喜欢<代码>delegate<>syntax。

问题回答

借助(或以母集装箱为单位的)类别或类似类别或根据母体集装箱确定这种联系。 然后使用寿命。

<script id="movieTemplate" type="text/x-jquery-tmpl">
    <div id="xyz"><a class="tmplClick">${link}</a> </div>
</script>

之后:

$( a.tmplClick ).live( click ,function(){
    alert( clicked in template );
});




相关问题
Check session from a view in CodeIgniter

What is the best way to check session from a view in CodeIgniter, it shows no way in their user guide, otherwise I will have to make two views on everything, which is kinda weird...still a newbie to ...

How to create a submit button template in Oracle APEX?

I m trying to create a template for a button in Oracle APEX but I don t seem to have access to the appropriate substitution strings to make it work. For non-templated buttons APEX seems to insert a ...

list of controls with templates in silverlight

Does anyone know where to find a list of controls that you can set the template on in Silverlight? I ve wasted several hours now trying to create control templates only to find that the control doesn ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Load ruby on rails template from database

I wonder if there is a way for me to store ruby on rails view files into database store and have that fetched directly from there. The reason is I want to create a CMS with all the user data stored in ...

Templated HTML Editor

I m looking for a HTML editor that kinda supports templated editing or live snippets or something like that. Background: I m working on a website for a friend. As there are no specifications what the ...

Dreamweaver changing path to site s reference instead of local

I have noticed recently, when I apply a template to a new HTML website, all the relative paths are pointed to my local files, example: file:///C|/webstuff/files but I cannot set them to relative paths ...

WPF ListView : Header styling

I want to have a ListView with columns and a particular style: The background for ALL column headers should be transparent except when the mouse is over in one of them. When this happends, the ...

热门标签