简体   繁体   English

jQuery-更改html 标签的内容

[英]jquery - change content of html <b> tag

I have set of frames and html pages . 我有一套框架和HTML页面。 I have selected one of the frames html element from another html page and I want to change the content using jquery. 我已经从另一个HTML页面中选择了框架html元素之一,我想使用jquery更改内容。

Here , I want to change "test.com" to "something.com" . 在这里,我想将“ test.com”更改为“ something.com”。 Please let me know , how to achieve this. 请让我知道,该如何实现。

HTML element in frame 0 : 第0帧中的HTML元素:

<span class="topmid-left">Connected to <b>My Site 'test.com' </b> </span>

The same element can be selectable by jquery by setting context : jQuery可以通过设置context来选择相同的元素:

**query -**  $("b",window.frames[0].document)

**result -** <b>​My Site 'test.com' ​</b>​

How to change the content of tag here. 如何在此处更改标签的内容。

Thanks. 谢谢。

Here is the fiddle: https://jsfiddle.net/swaprks/L1rq4o7a/ 这是小提琴: https : //jsfiddle.net/swaprks/L1rq4o7a/

Use jquery and add the following to your javascript: 使用jquery并将以下内容添加到您的javascript中:

$(".topmid-left b").html("My Site 'something.com'");

try this: 尝试这个:

<script>
var str = 'your text';
$( "b" ).html( str );
or 
$("b").text(YOUR_TEXT)
</script>

Learn More 学到更多

Try this it will work : 试试这个将起作用:

Html : HTML:

<span class="topmid-left">Connected to <b>My Site 'test.com'</b> </span>

Script : 剧本:

// return the inner text of <b>.
var boldText = $("span.topmid-left b").text(); 

// returns the array of length 3.
var splitArr = boldText.split('\''); 

// returns test.com
var text = splitArr[1];

// replace the text.com with abc(or any text you want).
var repText = boldText.replace(text, "xyz"); 

// [Output] My Site 'xyz'
console.log(repText);

// assign new text into html <b> tag.
$("span.topmid-left b").text(repText);

Working Jsfiddle : https://jsfiddle.net/LxcLb012/2/ 工作中的Jsfiddle: https ://jsfiddle.net/LxcLb012/2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM