我正在尝试将onClick处理程序添加到嵌入对象.处理程序需要执行一个函数,该函数位于外部.js文件中,该文件通过链接到当前的html文件<script src="...
.
我是否需要以不同的方式引用该功能,因为它位于其他位置?
这是当前的代码(不起作用,但也不会产生任何错误):
<embed src="svg/button.svg" id="buttonEmbed" width="95" height="53"
type="image/svg+xml" onClick="buttonEvent('buttonClicked')"/>
Run Code Online (Sandbox Code Playgroud) 我扩展了Array
原型:
if(typeof Array.prototype.filter === 'undefined') Array.prototype.filter = function(fun /*, thisp*/){
var len = this.length;
if(typeof fun != "function") throw new TypeError();
var res = [], thisp = arguments[1];
for(var i=0;i<len;i++){
if(i in this){
var val = this[i]; // in case fun mutates this
if(fun.call(thisp, val, i, this)) res.push(val);
}
}
return res;
};
Run Code Online (Sandbox Code Playgroud)
例如,我创建了数组:
var A = [ 1, 2, 3, 4, 5 ];
Run Code Online (Sandbox Code Playgroud)
然后我添加了额外的属性,我将使用:
A.creator = 'Rustam';
A.created = new Date();
Run Code Online (Sandbox Code Playgroud)
如果我将使用for-in
循环,并且浏览器没有内置支持Array.filter
,它将通过A.filter …