[英]“javascript:” prefix in an html attribute
I've noticed that some third party libraries use the "javascript:" prefix before a method, in an html variable. 我注意到一些第三方库在方法之前使用“javascript:”前缀,在html变量中。 I am not an advocate of inline javascript, but am curious to know what it does?
我不是内联javascript的拥护者,但我很想知道它的作用是什么?
Here is an example: 这是一个例子:
data-permalink="javascript:nRelate.xgeba('meta', 'property', 'og:url')0.content;"
I anticipate that the prefix is meant to allow the method call to execute and assign a value dynamically to the attribute, but this piece of test code tells me differently: http://codepen.io/anon/pen/HxzBa . 我预计前缀是为了允许方法调用执行并动态地为属性赋值,但这段测试代码告诉我不同的方式: http : //codepen.io/anon/pen/HxzBa 。
The library is probably using that data attribute verbatim as an href
for an a
tag. 该库可能使用该数据逐字属性为
href
为a
标签。 When placed thusly, the code will execute when the link is clicked. 如此放置,代码将在单击链接时执行。
Otherwise, javascript put as the value of data-*
attributes will not auto-execute. 否则,javascript作为
data-*
属性的值将不会自动执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.