gpt4 book ai didi

jquery - 通过 JQuery 替换父 DIV 下子级中的文本

转载 作者:行者123 更新时间:2023-12-01 04:14:22 25 4
gpt4 key购买 nike

我想将文本中的(访问被拒绝。请登录或注册。)更改为“您无权访问”以下代码:-

<div class="messages error">
<h2 class="element-invisible">Error message</h2>
Access denied. Please Login or Register.
</div>

我尝试在 Ready Function 中使用以下代码,但它无法正常工作。

$("div.messages").text(function () {
console.log($(this).text());
return $(this).text().replace("Access denied. Please Login or Register.", "You are not authorized to access");
});

谢谢。

<小时/>

还有其他办法吗?它给了我错误

Uncaught TypeError: Cannot set property 'nodeValue' of undefined ... 

最佳答案

$("div.messages h2")
.prop('nextSibling')
.nodeValue = "You are not authorized to access";

http://jsfiddle.net/ZwLKZ/

$("div.messages").contents().filter(function() {
return this.nodeType === 3 && $.trim(this.nodeValue) !== '';
}).get(0).nodeValue = "You are not authorized to access";

关于jquery - 通过 JQuery 替换父 DIV 下子级中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16220456/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com