我正在动态创建一个按钮。我可以传递一个带有数值 (1) 的变量,但我不能传递一个字符串变量。为什么?
function test(test1) {
alert(test1);
}
document.write("<input type='button' value='' id=j onclick='test(1)'/>");
你当然可以。您只需要添加引号。
function test(test1) {
console.log(typeof test1);
}
document.write("<input type='button' value='Click' id='j' onclick='test(\"abc\")'/>");
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句