为什么我不能从内联锚点调用该对象的函数?
HTML:
<a href="javascript:alert('Hey.')">Alert</a><br/>
<a href="javascript:alert('In anchor:\n' + objection.sustained());">Alert</a>
Javascript:
var objection = {
sustained : (function() {return ("accroches-toi a ton reve")})
};
alert("In script: \n" + objection.sustained());
$("outdat").text( +"<br/>\n");
只是好奇,为什么我不能调用 objection.sutain()
来自锚标记,但是可以从脚本区域执行此操作吗?
使用锚点时似乎甚至不知道该对象的存在。发生在几个主要浏览器中,所以我相信这是设计使然?
HTML:
<a href="javascript:alert('Hey.')">Alert</a><br/>
<a href="javascript:alert('In anchor:\n' + objection.sustained());">Alert</a>
Javascript:
var objection = {
sustained : (function() {return ("accroches-toi a ton reve")})
};
alert("In script: \n" + objection.sustained());
$("outdat").text( +"<br/>\n");
Just curious here, why can't I call objection.sustained()
from an anchor tag, but it's OK to do it from the script region?
It seems to not even know the object exists when using the anchor. Happens in several major browsers so I believe this is by design?
在 JSFiddle 上使用 No Wrapper(head) 或 No Wrapper(body)
Use No Wrapper(head) or No Wrapper(body) on JSFiddle