<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>

错误代码返回结果:

b函数的id:001
a函数的id:1

正确代码返回结果:

b函数的id:001
a函数的id:001

相关文章:

  • 2022-01-14
  • 2021-12-20
  • 2022-12-23
  • 2021-12-20
  • 2021-12-26
  • 2022-12-23
猜你喜欢
  • 2021-09-11
  • 2022-01-21
  • 2022-12-23
  • 2021-12-20
  • 2021-05-17
相关资源
相似解决方案