我在 powerapps 門戶中呈現了以下 HTML,我想替換所有出現的
<font size = 3>..... </font>
和
<div class="legend">... </div>
我已經嘗試了下面的代碼段,但它并沒有取代它:
var $descBox = $("<font size = 3>"); $descBox.replaceAll("<div class='legend well'>");
uj5u.com熱心網友回復:
- 要搜索現有元素,請使用 jQuery 中的 CSS 運算式
$()。 - 要創建新元素,請使用 jQuery 的
$(). .replaceAll()是一個字串函式。你的意思是.replaceWith()。
IE
$("font[size=3]").replaceWith( $("<div class='legend well'>") );
或者,更短
$("font[size=3]").replaceWith("<div class='legend well'>");
只交換<font>元素而不替換它們的內容需要幾個步驟。
$("font[size=3]").each(function () {
// insert new container div after each `<font>`
var $div = $("<div class='legend well'>").insertAfter(this);
// remove the `<font>` and append its children to the new container
$(this).remove().children().appendTo($div);
});
div.legend {
color: blue;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<font size="3">
<p>elements to keep</p>
</font>
<font size="3">
<p>more elements to keep</p>
</font>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/468999.html
標籤:javascript jQuery
下一篇:批量收集和游標之間的區別
