2

次のコードで(アクセスが拒否されました。ログインまたは登録してください。)のテキストを「アクセスする権限がありません」に変更したい:-

<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 ... 
4

1 に答える 1

2
$("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";
于 2013-04-25T16:53:30.140 に答える