darasion

<div id="aaa"> </div> 会在全局名字空间创建 aaa 变量,这个特性太扯淡了。

  •  
  •   darasion · Apr 23, 2012 · 4077 views
    This topic created in 5202 days ago, the information mentioned may be changed or developed.
    chrome 下测试:

    ======================================
    html 文件:
    <div id="aaa">testtest</div>

    ======================================
    console 输出:
    ------------------------------------------------------------
    >aaa
    <div id=​"aaa">​
    testtest
    ​</div>​
    ------------------------------------------------------------
    >typeof aaa
    "object"
    ------------------------------------------------------------
    >aaa.toString()
    "[object HTMLDivElement]"
    ------------------------------------------------------------

    我才发现。囧。

    本来我感觉 js 变量的命名就非常头疼,这下又加了一条头疼的规则。
    9 replies    1970-01-01 08:00:00 +08:00
    darasion
        1
    darasion  
    OP
       Apr 23, 2012   ❤️ 1
    @livid 有bug 啊,主题中的html都没过滤,赶快修啊赶快。。。
    dongsheng
        2
    dongsheng  
       Apr 23, 2012
    V2EX被XSS了
    Insomnia
        3
    Insomnia  
       Apr 23, 2012
    被弹窗了。。。
    ry_wang
        4
    ry_wang  
       Apr 23, 2012   ❤️ 1
    这是大漏洞...... @livid
    dongsheng
        5
    dongsheng  
       Apr 23, 2012   ❤️ 1
    @livid 赤裸裸的script标签被输出了
    vibbow
        6
    vibbow  
       Apr 23, 2012
    <script> alert('WTF,居然script会被解析?'); </script>
    Livid
        7
    Livid  
    MOD
    PRO
       Apr 23, 2012
    正在解决。
    Livid
        8
    Livid  
    MOD
    PRO
       Apr 23, 2012
    Fixed.

    Thank you.
    yyfearth
        9
    yyfearth  
       Apr 23, 2012
    其实也没啥啊,只是在变量使用的时候要小心一些罢了。
    而且本来在使用变量的时候都是用闭包的局部变量,很少去用全局的变量。
    这样用id,应该是为了一定程度上兼容ie吧(猜的)
    另外,debug的时候挺方便的。
    所有变量都在(function(){var xxx;...})里面声明,也不用管id啊。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3267 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 00:30 · PVG 08:30 · LAX 17:30 · JFK 20:30
    ♥ Do have faith in what you're doing.