jquery 替换元素
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<meta charset="utf-8" />
<script src="jquery-3.3.1.js"></script>
<script>
$(function () {
$('#btn').click(function () {
$('br').replaceWith('<hr color="yellow"/>');
//$('<hr color="yellow"/>').replaceAll('br');
});
$('#btn2').click(function () {
$('br').replaceAll('hr');
})
})
</script>
</head>
<body>
<input type="button" name="name" value="替换1" id="btn" /><br />
<input type="button" name="name" value="替换2" id="btn2" /><br />
静夜思<br />
床前明月光,<br />
疑是地上霜,<br />
举头望明月,<br />
低头思故乡。<br />
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<meta charset="utf-8" />
<script src="jquery-3.3.1.js"></script>
<script>
$(function () {
$('#btn').click(function () {
$('br').replaceWith('<hr color="yellow"/>');
//$('<hr color="yellow"/>').replaceAll('br');
});
$('#btn2').click(function () {
$('br').replaceAll('hr');
})
})
</script>
</head>
<body>
<input type="button" name="name" value="替换1" id="btn" /><br />
<input type="button" name="name" value="替换2" id="btn2" /><br />
静夜思<br />
床前明月光,<br />
疑是地上霜,<br />
举头望明月,<br />
低头思故乡。<br />
</body>
</html>