我的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

我究竟做错了什么?

最佳答案

您可能会考虑仅使用更通用的选择器(例如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>

10-05 20:53
查看更多