为了更好地理解JavaScript,并试图了解其原因,Google搜索导致没有答案(尽管我可能使用不正确的术语搜索)。为什么在调用我的javascript函数时需要'javascript:'?
我在<a></a>
内的onclick事件中正在调用函数。通过在创建函数之前添加'javascript:',我能够获得最终工作的功能(来自同事的建议)。没有onclick中的javascript:部分,我的函数没有被调用。
它现在可以工作,但我不明白这是做什么,另一位程序员谁建议把它在电话中也不知道它究竟做了什么。
这里所使用的代码的简化版本:
#1 .jspf higher up which includes page #2 to display it's contents
function createTagging(1, 2) {
cmCreateElementTag(1 + ", " + 2,"TagName");
}
HTML in .jspf file #2 further down website makes the call to function in file #1
<a id="CatEntry" href="https://aurl"
onclick="javascript: createTagging('parameter1', 'parameter2');"
title="atitle" aria-label="alabel">
<img id="ThumbNailImage_59244" src="https://image.jpg"
alt="" border="0"/>
</a>
-Troy
相关https://stackoverflow.com/questions/10877485/better-way-to-call-javascript-function-in-a-tag –