js坑 把数字型的字符串默认为数字 把前面的0给去掉了("001")

<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