<script>
b("001");
function b(id)
{
console.log("b函数的id:"+id);
//var history = "<a href='#' onclick='a(" +id + ")'>历史</a>"; 错误代码这里id默认理解成数字类型,需要"",直接在前面添加会影响html结构报语法错误所以需要把"需要转义\"
var history = "<a href='#' onclick='a(\"" +id + "\")'>历史</a>";
document.write(history)
}
function a(id)
{
console.log("a函数的id:"+id);
}
</script>
转载于:https://www.cnblogs.com/shuihanxiao/p/10250026.html
本文探讨了JavaScript中函数调用的过程,特别是在处理字符串参数时的注意事项。通过具体示例,展示了如何正确地在函数调用中使用字符串,避免因类型默认转换导致的错误。

被折叠的 条评论
为什么被折叠?



