开发者

Organising JavaScript / jQuery - alternative to using jQuery's live hookup

Simple question (I hope). I have a page that contains links that when clicked loads up new content into a specified div. The content that gets loaded (a partial view) contains further links that fire JavaScript code (jQuery).

I have been hooking these links up using jQuery's live system. It has been recommended to me that I wire-up the buttons in the partial views by placing JavaScript directly into these views or by adding onclick handlers directly to the links (rather than wiring them up with jQuery).

Is there a 'best practice' to hooking up dynam开发者_JAVA技巧ic content?


I would argue against in-line JavaScript, be it in a script tag or in onclick handlers. Separation from your presentation logic is always recommended.

As for what to do in that instance, I'd say your best bet would be to use live events or to make use of a callback to assign additional functionality. REF: http://api.jquery.com/jQuery.ajax/


Both solutions are ok, but I consider messy adding javascript calls in my partials... so I'd use live


no - ideally you should not use inline event handlers. Ideally you should assign events using js or if its a link use an anchor tag

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜