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>

posted @ 2019-01-10 14:57  shuihanxiao  阅读(2083)  评论(0编辑  收藏  举报