[英]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()
doesn't seem to work. Wrap()
似乎不起作用。 I don't see <span>
s wrapped around input in firebug. 我在Firebug中看不到
<span>
包裹输入。 If they were wrapped, inputs would be hidden with display: none
, but they aren't. 如果将它们包装起来,则输入将被
display: none
隐藏display: none
,但不是。
What am I doing wrong here? 我在这里做错了什么?
Works ok for me. 为我工作正常。 Is it possible that you have a javascript error on the page that is preventing the code from executing?
页面上是否存在javascript错误,阻止了代码执行?
Here's my test. 这是我的测试。 Element does become invisible and I can see that it is wrapped in the span.
元素确实变得不可见,我可以看到它包裹在跨度中。
<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.