代码之家  ›  专栏  ›  技术社区  ›  eozzy

jquery wrap()不工作

  •  1
  • eozzy  · 技术社区  · 16 年前

    HTML:

    <input type="text" class="text text-1" />
    

    JQuery

    $('input.text-1').wrap('<span class="textfield-1"></span>');
    

    CSS:

    .textfield-1 {
        border: 1px solid #d00;
        display: none;
    }
    

    wrap()似乎不起作用。我看不出Firebug中的输入被包装了。如果将它们包装起来,输入将被显示隐藏:没有,但没有。

    我在这里做错什么了?

    谢谢

    1 回复  |  直到 16 年前
        1
  •  1
  •   tvanfosson    16 年前

    对我来说没问题。是否有可能页面上有阻止代码执行的javascript错误?

    这是我的测试。元素确实变得不可见,我可以看到它被包裹在跨度中。

    <html>
    <head>
    <style type="text/css">
    .textfield-1 {
        border: 1px solid #d00;
        display: none;
    }
    </style>
    <script type="text/javascript" language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/javascript" language="javascript">
    
        $(function(){
                $('input.text-1').wrap('<span class="textfield-1"></span>');
         });
    
    
    </script>
    </head>
    <body>
    <input type="text" class="text text-1" />
    </body>
    </html>
    
    推荐文章