使用 jquery 更改链接中的 html 文本 [英] change html text from link with jquery

查看:24
本文介绍了使用 jquery 更改链接中的 html 文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有个简单的问题

有没有办法改变文字点击这里"

Is there a way to change the text "click here"

<a id="a_tbnotesverbergen" href="#nothing">click here</a>

在这个链接中

理查德

推荐答案

你必须使用 jquery 的 text() 函数.它的作用是:

You have to use the jquery's text() function. What it does is:

获取所有的组合文本内容匹配的元素.

结果是包含组合文本的字符串所有匹配元素的内容.这方法适用于 HTML 和 XML文件.不能用于输入元素.对于输入字段文本使用val 属性.

The result is a string that contains the combined text contents of all matched elements. This method works on both HTML and XML documents. Cannot be used on input elements. For input field text use the val attribute.

例如:

在第一段中找到文本(去掉html),然后设置最后一段的 html 来显示它只是文本(粗体消失了).

Find the text in the first paragraph (stripping out the html), then set the html of the last paragraph to show it is just text (the bold is gone).

var str = $("p:first").text();
$("p:last").html(str);

测试段落.

测试段落.

使用您的标记,您必须:

With your markup you have to do:

$('a#a_tbnotesverbergen').text('new text');

它会导致

<a id="a_tbnotesverbergen" href="#nothing">new text</a>

这篇关于使用 jquery 更改链接中的 html 文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆