87,712
社区成员




<html>
<head>
<script>
function model(){
this.a=1;
this.b=2;
}
function test(a){
alert(a);
}
</script>
</head>
<body>
<script>
var a=new model();
document.write('<button onclick="test('+a+')">aaa</button>');
//test(a);
</script>
</body>
</html>
'<button onclick="test('+a+')">aaa</button>'
因为上面的写法,a会被转成字符串,不会执行。
你可以这么写:
'<button onclick="test(window.a)">aaa</button>'