2016-04-15 2 views
0

javascriptまたはテンプレートが壊れています。エラーコードをjavascriptで変更する

これはエラーメッセージを変更するための私のジャバスクリプトです。テンプレートにアクセスできないため、テンプレートを変更できません。

<!-- CHANGE ERROR MESSAGE --> 
<script language="JavaScript"> 

    $(function() { 
    $.ajaxSetup({complete: function() { 
     $(".errorExplanation ul li:contains('Password and email do not match')").ReplaceWith('Password does not match');}}) 
    }); 

</script> 

これが翻訳されることを拒否し、ウェブサイトの一部です:

The code of the page

私が間違って何をしているのですか?

+1

は小文字である必要があり、これを試してみてください。 –

+0

動作しません。私は小文字や大文字とは関係ないと思います。私はエラーコード 'パスワードと電子メール..'は私が(まだ)理解していない別のセクションの一部だと思います。 –

答えて

1

あなたはちょうどそのようなspan.error-message:contains('...')など、より一般的なセレクタを使用してコンテンツだけを設定するためにjQueryのtext()機能を使用して検討するかもしれない:

$("span.error-message:contains('Password and email do not match')").text('Password does not match'); 

あなたはそれをより具体的にする必要がある場合、あなたは#patternのような識別子を使用することができますあなたの例のコードから:

$("#pattern span.error-message:contains('Password and email do not match')").text('Password does not match'); 

あなたは以下に示す非常に基本的な例を見ることができます:

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<script src="https://code.jquery.com/jquery-2.1.4.js"></script> 
 
    <meta charset="utf-8"> 
 
    <meta name="viewport" content="width=device-width"> 
 
    <title>JS Bin</title> 
 
</head> 
 
<body> 
 
    <pre>Original</pre> 
 
    <span class='original-error-message'> 
 
     Password and email do not match 
 
    </span> 
 
    <pre>Replaced</pre> 
 
    <span class='error-message'> 
 
     Password and email do not match 
 
    </span> 
 
    
 
<script language="JavaScript"> 
 
    $(function() { 
 
     // Replace any spans with class 'error-message' that contain 
 
     // your specific text 
 
     $("span.error-message:contains('Password and email do not match')").text('Password does not match'); 
 
    }); 
 
    </script> 
 
</body> 
 
</html>

+0

ご返信ありがとうございます。残念ながら、それは動作していません。それは.htmlの部分かもしれないが、私は本当にそれがいくつかのセクションだと思う。 –

+0

私は 'text()'を使うように更新しました。これはプレーンテキストを使っているだけで、動作する例が追加されているのでより適切です。 –

+0

魅力のように動作します、ありがとうございます!良い週末を。 –

0

それを簡単に、テキストを置き換えるために.text()メソッドを使用します。

$(function(){ 
    $("span.error-message").text('Password does not match'); 
}) 
0

R .replaceWith

$('.error-message span').html('Password does not match'); 
関連する問題