miniyao
V2EX  ›  问与答

javascript 传不了 uuid 长度的参数吗?

  •  
  •   miniyao · Jan 11, 2019 · 2292 views
    This topic created in 2693 days ago, the information mentioned may be changed or developed.

    用数字 item.id ,可以正常传值,换 item.uuid 就传不了,是什么问题:

    <div id={{ item.uuid }}>
    ...
    <a href="#" onclick="test(this, {{ item.uuid }}">TEST</a>
    ...
    </div>
    
    <script type="text/javascript">
    function test(obj, item_uuid {
        alert(item_uuid);
    }
    </script>
    
    

    alert 弹不出来 item_uuid 的值,把 uuid 去掉横杠-,直接 hex 后表示成 32 位字符串 b1ec313a156411e9a2e80800273a332b 还是不行。只有把 uuid 换成数字 id,才能传值成功,alert 可以正确显示。这是什么问题?为什么只能传数字 id ? uuid 的字符串传不了?

    9 replies    2019-01-11 15:44:51 +08:00
    shylocks
        1
    shylocks  
       Jan 11, 2019 via iPhone   ❤️ 1
    (this,‘ {{ item.uuid }’)
    Phariel
        2
    Phariel  
       Jan 11, 2019 via iPhone   ❤️ 1
    '{{item.uuid}}'
    dallaslu
        3
    dallaslu  
       Jan 11, 2019
    看看最终输出的 html 源码吧
    miniyao
        4
    miniyao  
    OP
       Jan 11, 2019
    @shylocks
    @Phariel

    谢谢,引号不能少
    Pastsong
        5
    Pastsong  
       Jan 11, 2019
    JS 哭晕了
    miniyao
        6
    miniyao  
    OP
       Jan 11, 2019
    @Pastsong
    @dallaslu

    以前遇到过带横线的 uuid 传值出现问题,以为是 uuid 的字符串有什么问题
    TomatoYuyuko
        7
    TomatoYuyuko  
       Jan 11, 2019
    可以理解为{{}}只是个占位符而已,内容是啥渲染完就是啥,值不带引号,渲染完也同样没引号
    autoxbc
        8
    autoxbc  
       Jan 11, 2019
    这种问题在控制台会有提示
    lzvezr
        9
    lzvezr  
       Jan 11, 2019 via Android
    感觉已经看不懂 JavaScript 了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4273 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 05:29 · PVG 13:29 · LAX 22:29 · JFK 01:29
    ♥ Do have faith in what you're doing.