繁体   English   中英

wrap()方法在jQuery中似乎不起作用

[英]wrap() method doesn't seem to work in jQuery

 $('input.text-1').wrap('<span class="textfield-1"></span>'); 
 .textfield-1 { border: 1px solid #d00; display: none; } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input type="text" class="text text-1" /> 

Wrap()似乎不起作用。 我在Firebug中看不到<span>包裹输入。 如果将它们包装起来,则输入将被display: none隐藏display: none ,但不是。

我在这里做错了什么?

为我工作正常。 页面上是否存在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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM