すべての辞書
jQuery 関連辞書
jquery replaceWith()方法
使用方法の詳細
jquery replaceWith()方法
中国語翻訳
最近の更新: 2018-05-11 15:32:28
replace
UK[rɪˈpleɪs] US[rɪˈples]
vt. 置き換える; 置き換える;...を元の位置に戻す; (...を使用する)
with
英[wɪð] 美[wɪθ]
prep.With;and,with;about;consistent with...
jquery replaceWith()方法 構文
関数: replaceWith() メソッドは、選択した要素を指定された HTML コンテンツまたは要素に置き換えます。 replaceWith() は replaceAll() と同じ効果があります。違いは構文にあり、セレクターの内容と位置が異なり、置換には replaceAll() 関数を使用できません。
##構文: $(selector).replaceWith(content)
| 説明 | |
| 必須。選択した要素を置き換えるコンテンツを指定します。可能な値: HTML コード - 例: (" gt; ") 新しい要素 - 例: (document.createElement("div")) 既存の要素 - 例: ($(".div1")) 既存の要素は移動することはできません。選択した要素をコピーしてラップするだけです。 | |
| 必須。置換する要素を指定します。 |
関数を使用して、選択した要素を新しいコンテンツに置き換えます。
# 構文:$(selector).replaceWith(function())
| 説明 | |
必須。選択した要素を置き換える新しいコンテンツを返す関数。 #####################################
jquery replaceWith()方法 例<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".btn1").click(function(){
$("p").replaceWith("<b>Hello world!</b>");
});
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button class="btn1">用粗体文本替换所有段落</button>
</body>
</html>[インスタンスの実行] ボタンをクリックしてオンライン インスタンスを表示します |




