开发者

jQuery replacewith

开发者 https://www.devze.com 2023-04-12 02:06 出处:网络
I was wondering if it is possible to replace a part of a string with var开发者_StackOverflowiable.

I was wondering if it is possible to replace a part of a string with var开发者_StackOverflowiable.

basically what I want to do is the following I want to replace [socialnetworks] with the social network code.

the way it gets the code is via $.POST as it has to fetch this from the mysql database via PHP


You could try something like this.

$("*").each(function () { 
if ($(this).children().length == 0) { 
  $(this).text($(this).text().replace('[socialnetworks]',variable)); 
   } 
});


var code = "<p>Something</p>";
yourString.replace("[socialnetworks]", code);

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/replace

I don't know if it's what you wanted ;).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号