1、替换某个指定元素的内容,比如
$(document).ready(function(){$("p").html("Hello <b>world</b>!");$("p").text("你好");$("#ksy").html("Hello <b>world</b>!");
});
区别是html方法是支持html标签,text方法是字符串。
2、方法二
$(document).ready(function(){
$("<span>Hello world!</span>").replaceAll("p:last"); //replaceAll方法
$("p:first").replaceWith("Hello world!"); //replaceWith方法
});
3、替换某个元素里面字符串指定的内容
//方法一
$(document).ready(function(){
var str = "要替换的字符串内容";
var newStr = place(/要替换/g, "你好");
alert(newStr);
});
//方法二
$(document).ready(function(){
var htmls = $("#main").html();
var html_new = place(/要替换的字符串/g, "新的字符串内容");
$('#main').html(html_new);
});
本文发布于:2024-01-29 16:59:34,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170651877916842.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |