1
使用jQuery和backbone.js,我想尽可能地从HTML中分离JavaScript。
是否可以添加custom attribute
以更好地区分JavaScript和HTML? 然后我该如何使用新的jQuery选择器?添加自定义属性以更好地区分JavaScript和HTML
例子:
<input type="text" id="todo-input" class="todo-input" tid="tid-attribute" > hello world </input>
// The DOM events
// I would like to use another selector tid and not class or id
events: {
"keypress #todo-input" : "updateOnEnter" // I would like to use another selector tid not id,
"keypress .todo-input" : "updateOnEnter" // I would like to use another selector tid and not class
}
我还是不明白这一点。你想分离吗?或者属性会打扰你。据我所知,这是视图的工作,不要渲染骨干应用程序的任何服务器依赖。这将使您的骨干应用部署在任何地方。 – Deeptechtons
HTML'class'属性用于各种事物,而不仅仅用于CSS样式。向元素添加额外的类只是为了在选择器中使用没有任何问题。 –