gpt4 book ai didi

jquery - 在()之前使用 jQuery : Wrapping div in another div with .

转载 作者:行者123 更新时间:2023-12-01 02:46:05 25 4
gpt4 key购买 nike

我正在尝试使用 jQuery 在以下代码周围添加一个 div:

<div class="fsSubField">
<input id="field15744501-zip" class="fsField fsFieldZip fsFormatZipCA" type="text" value="" size="8" name="field15744501-zip">
<br>
<label class="fsSupporting" for="field15744501-zip">Postal Code</label>
</div>

所以最后我有:

<div class="fsSubFieldGroup" style="margin-top:5px;">
<div class="fsSubField">
<input id="field15744501-zip" class="fsField fsFieldZip fsFormatZipCA" type="text" value="" size="8" name="field15744501-zip">
<br>
<label class="fsSupporting" for="field15744501-zip">Postal Code</label>
</div>
</div>

我尝试了以下方法:

$('input.fsFormatZipCA').parent().before('<div> class="fsSubFieldGroup" style="margin-top:5px;">');
$('input.fsFormatZipCA').parent().after('</div>');

由于表单的动态特性,我需要能够基于“input.fsFormatZipCA”进行选择

我认为这会起作用,但问题是 jQuery 正在执行以下操作:

<div class="fsSubFieldGroup" style="margin-top: 5px;"></div>
<div class="fsSubField">
<input id="field15744501-zip" class="fsField fsFieldZip fsFormatZipCA" type="text" value="" size="8" name="field15744501-zip">
<br>
<label class="fsSupporting" for="field15744501-zip">Postal Code</label>
</div>

最佳答案

您似乎正在寻找.wrap:

$('input.fsFormatZipCA').parent().wrap(
$('<div>', {
'class': 'fsSubFieldGroup', // class is a reserved word
css: {
'margin-top': 5 // - is an invalid identifier character
}
})
);

.before 在元素之前插入一个元素。它不会通过简单地在前面添加 HTML 字符串来构造 HTML。

关于jquery - 在()之前使用 jQuery : Wrapping div in another div with .,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10805083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com