jquery replaceall()的使用方法
replaceAll() 方法用指定的 HTML 内容或元素替换被选元素。
提示:replaceAll() 与 replaceWith() 作用相同。差异在于语法:内容和选择器的位置,以及 replaceWith() 能够使用函数进行替换。
$(content).replaceAll(selector)
<html>
<head>
<script type="text/网页特效" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("<b>Paragraph. </b>").replaceAll("p");
});
</script><style>
div { border:2px green solid;}
</style>
</head>
<body>
<body>
<p>Hello</p></body>
</html>
看实例二 (选择):replaceAll 2,3,6,7,11,14]的补充,replaceWith() www.zhutiai.com
<html>
<head>
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){$("<b>Paragraph. </b>").replaceAll("span");
});
</script>
</head>
<body>
<body>
<span>Span Text www.zzzyk.com </span>
</body>
</html>
替换所有button的文本说明
<html>
<head>
<script type='text/javascript' src='js/jquery-1.3.2.js'></script>
<script type='text/javascript'>
$(document).ready(
function() {
$('input#id1').click(
function($e) {
$e.preventDefault();
$(this).replaceWith(
"<p>replaced</p>"
);
}
);
$('input#id2').click(
function($e) {
$e.preventDefault();
$(this).replaceWith(
"<p>replaced</p>"
);
}
);
}
);
</script></head>
<body>
<div>
<input type='submit' id='id1' value='View Quote' />
</div>
<div>
<input type='submit' id='id2' value='View Quote' />
</div>
</body>
</html>
最后给个参考表
参数 | 描述 |
---|---|
content |
必需。规定替换被选元素的内容。 可能的值:
已存在的元素不会被移动,只会被复制,并包裹被选元素。 |
selector | 必需。规定要替换的元素。 |
补充:网页制作,jquery