摘要:[jQuery]用指定的HTML內容或元素替換被選擇的元素(replaceWith)
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>replaceWith demo</title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<p><label id="change">測試初始內容</label></p>
<p><input id="content" type="text" placeholder="請輸入想要的資料" /></p>
<input id="touch" type="button" value="Action" />
<script>
$("#touch").click(function(){
var content=$("#content").val();
if(content == ""){
content="沒有輸入資料唷!";
}
$("#change").replaceWith("<label id='change'>"+content+"</label>");
});
</script>
</body>
</html>