开发者

Jquery in views

Is it OK (It's working OK but is it proper?) if I place jquery code:

<script>
  $(function() {
    $( "开发者_Go百科#accordion" ).accordion();
  });
</script>

in my app/views/show.html.rb ?

Is it better to put it somewhere else? I didn't want to put it in layout because I don't need it anywhere else.


Personally I would put that piece of script into an external JS file and call it from the header of my page in my layout - this way you are keeping your markup and your Javascript entirely separate (in much the same way that you would put all your CSS in an external CSS file and not in style attributes).

But there is no harm in having it where it is. It's really up to you whether you feel it is worth the time and effort to move the script into an external file.


I think It's better if you put your code in a .js file and include it only when you need it.

Hope this helps. Cheers

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜