jQuery获取文本
我有一个函数,返回一些html,如下所示:jQuery获取文本,jquery,jquery-selectors,Jquery,Jquery Selectors,我有一个函数,返回一些html,如下所示: return ("<span class='opt'>some text</span>"); html给出元素。我只想检索没有标签的文本。我用format(html).text()尝试过,但不起作用。有什么想法吗?$('some text')。text()应该做这项工作,或者在您的情况下: $(tag).append($(format(html)).text()); $('some text')。text()应该完成这项工作
return ("<span class='opt'>some text</span>");
html
给出
元素。我只想检索没有标签的文本。我用format(html).text()尝试过,但不起作用。有什么想法吗?$('some text')。text()
应该做这项工作,或者在您的情况下:
$(tag).append($(format(html)).text());
$('some text')。text()
应该完成这项工作,或者在您的情况下:
$(tag).append($(format(html)).text());
这将获取文本“…
”,将其转换为jQuery对象,并提取文本,留下标记
这将获取文本“
…
”,将其转换为jQuery对象,并提取文本,留下标记。如果要对HTML字符串执行jQuery操作,请先使用jQuery将其转换:
var newContent = $(format(html)); // use the results of `format(html)` to make a jQuery selection
$(tag).append(newContent.text()); // use the jQuery text method to get the text value of newContent
.如果要对HTML字符串执行jQuery操作,请先使用jQuery进行转换:
var newContent = $(format(html)); // use the results of `format(html)` to make a jQuery selection
$(tag).append(newContent.text()); // use the jQuery text method to get the text value of newContent
.您在那里的
文本之后缺少()
。您将在jQuery源代码中附加一部分!是的,刚刚意识到并修复了:-)在文本之后缺少()
。您将在jQuery源代码中附加一部分!是的,刚刚意识到并修复了:-)