cmdn_wangqian_yan
绵羊小
采纳率100%
2017-05-02 09:10 阅读 1.3k

Json字符串传值问题,希望点击事件不报错

各位大神,下边的html代码,点击dd标签时,能不报错,alert出来结果就是我的目的,求帮助。

 <html>
<head>
<title>测试</title>
<script>

function ShowLink(obj,item)
{
alert(obj.key);
}
</script>
</head>
<body>
<dd id="879CCBCF-A39A-4912-844D-669A74BEE9A3" onclick="ShowLink("[{"key":"size","type":null,"until":null,"default":null,"value":[{"name":"85.50*54.00*0.38","code":"85.50*54.00*0.38","isselect":true,"$$hashkey":"object:7489"},{"name":"85.50*54.00*0.76","code":"85.50*54.00*0.76","isselect":true,"$$hashkey":"object:7490"}],"$$hashkey":"object:7484"},{"key":"craftcodes","type":null,"until":null,"default":null,"value":[],"$$hashkey":"object:7485"}]",this)">亮光卡</dd>
</body>
</html>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    showbo GoCityPass新加坡曼谷通票 2017-05-02 09:20

    大数据不要存储在dom属性里面,要不字符串闭合有得搞

      <script>
    
            function ShowLink(obj,item)
            {
                alert(obj[0].key);
            }
        </script>
    </head>
    <body>
        <dd id="879CCBCF-A39A-4912-844D-669A74BEE9A3" onclick='ShowLink([{"key":"size","type":null,"until":null,"default":null,"value":[{"name":"85.50*54.00*0.38","code":"85.50*54.00*0.38","isselect":true,"$$hashkey":"object:7489"},{"name":"85.50*54.00*0.76","code":"85.50*54.00*0.76","isselect":true,"$$hashkey":"object:7490"}],"$$hashkey":"object:7484"},{"key":"craftcodes","type":null,"until":null,"default":null,"value":[],"$$hashkey":"object:7485"}],this)'>亮光卡</dd>
    </body>
    
    点赞 4 评论 复制链接分享

相关推荐