[英]How to use this code as Unobtrusively?
How to use this code as Unobtrusively? 如何毫不干扰地使用此代码? To keep content and Behaviour separate. 保持内容和行为分开。
<a href="nojavascript.html" onclick="functionName(); return false;"
onkeypress="functionName(); return false;">Link text</a>
You could write it like this: 您可以这样写:
<a href="nojavascript.html">Link text</a>
Then use jQuery's .bind()
like this: 然后像这样使用jQuery的.bind()
:
$("a[href$='nojavascript.html']").bind("click keypress", function() {
functionName();
return false;
});
Or alternatively, give it a class like this: 或者,给它一个这样的类:
<a class="noJS" href="nojavascript.html">Link text</a>
And use a .class
selector like $("a.noJS")
instead to be a bit cleaner (or, if it's unique, use an ID). 并使用$("a.noJS")
类的.class
选择器代替它,以使其更$("a.noJS")
(或者,如果唯一,则使用ID)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.