miniyao
V2EX  ›  问与答

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

  •  
  •   miniyao · Jan 11, 2019 · 2768 views
    This topic created in 2872 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
    shylocks
    Jan 11, 2019 via iPhone❤️1
    1
    (this,‘ {{ item.uuid }’)
    Phariel
    Phariel
    Jan 11, 2019 via iPhone❤️1
    2
    '{{item.uuid}}'
    dallaslu
    dallaslu
    Jan 11, 2019
    3
    看看最终输出的 html 源码吧
    miniyao
    miniyao
    OP
    Jan 11, 2019
    4
    @shylocks
    @Phariel

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

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