I'm working at the moment in a big ajax intense Web Project using JQuery and Grails extensively.
At the moment I'm asking myself how to make the code as mantainable as possible. Thus the question would be, in your opinion, it is better to completely separate the JS from the html (and make开发者_运维问答 use of Selectors and thus have clean HTML code), or mix both of them.
As an example, let's assume I have a tag which creates a comment system:
def commentTag = {
out << """
<div id="commentBox1" class="comment">
<input type="text" name="comment-something"/>
<input type="submit" value="comment"/>
</div>
<g:javascript>$('#commentBox1').commentSystem();</g:javascript>
"""
}
The question would be regarding the last line. Do you think it is a good design idea to include the JS code there, or would it be better to do it in a separate JS file. And then use some JQuery selector to apply the commentSystem behavior like this:
$('.comment').commentSystem();
Thanks for your help!
Regards, Nicolas
IMO, Its good to keep them separate in JS files, but whenever you are creating TagLib, code specific to that tag say commentTag which isn't used anywhere else, is better to be with commentTag only.
精彩评论