我有一个要求,我必须将此HTML代码替换为新的HTML代码
当前的Html `
<td class="dataCol first "><div class="requiredInput">
<div class="requiredBlock"></div>
<select id="pageLeadNew:frmLeadNew:pbLeadNew:pbsCorporateAccounts:IdCompanyTyp" name="pageLeadNew:frmLeadNew:pbLeadNew:pbsCorporateAccounts:IdCompanyTyp" onchange="FuntomangeCorpSection();"><option value="">--None--</option><option value="Sub National">Sub National</option>
<option value="Regional Account">Regional Account</option>
<option value="Hotel">Hotel</option>
<option value="Embassy">Embassy</option>
<option value="Fleet Operator">Fleet Operator</option>
<option value="Association">Association</option>
<option value="Others">Others</option>
</select></div></td>
`
必需的HTML `
<td class="dataCol first ">
<select id="pageLeadNew:frmLeadNew:pbLeadNew:pbsCorporateAccounts:IdCompanyTyp" name="pageLeadNew:frmLeadNew:pbLeadNew:pbsCorporateAccounts:IdCompanyTyp" onchange="FuntomangeCorpSection();"><option value="">--None--</option><option value="Sub National">Sub National</option>
<option value="Regional Account">Regional Account</option>
<option value="Hotel">Hotel</option>
<option value="Embassy">Embassy</option>
<option value="Fleet Operator">Fleet Operator</option>
<option value="Association">Association</option>
<option value="Others">Others</option>
</select></td>`
我必须删除当前的Html代码,其中包含必需的html代码,我必须将其移除到具有类名 requiredInput 和 requiredBlock <的 请提前帮助谢谢!! !! 答案 0 :(得分:0) Unwrap,从DOM中删除匹配元素集的父节点,将匹配的元素留在原位。 答案 1 :(得分:0) 假设你有jQuery 2 个答案:
$('.requiredInput').contents().unwrap();
$('.requiredBlock').remove()
var datacol = $('td.dataCol.first');
datacol.find('div.requiredBlock').remove();
datacol.find('div.requiredInput').contents().unwrap();