我必须编写一个函数来创建a标签的 HTML 代码,这个函数还将一个函数处理程序传递给onclick创建的a标签事件。代码:
function a(text,functionHandler){
return '<a href="#" onclick="'+functionHandler+'">'+text+'</a>';
}
//usage
var a1 = a('link',function(){
alert('test');
});
Run Code Online (Sandbox Code Playgroud)
将函数传递给字符串不起作用。所以我的问题是:how to pass a function handle to onclick event and get a HTML code of created a tag?
例如,这有什么区别:
element{
property1: val1;
property2: val2;
}
Run Code Online (Sandbox Code Playgroud)
还有这个:
element{
property2: val2;
property1: val1;
}
Run Code Online (Sandbox Code Playgroud)
?
更新我的意思是不同的属性,例如width和padding.