javascript - 使用 javascript 更改错误代码

标签 javascript

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

关于javascript - 使用 javascript 更改错误代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36655934/

相关文章:

javascript - 如何根据索引位置映射数组

javascript - 单击循环按钮时按钮文本发生变化

javascript - jquery Menu State使用父类

javascript - HTML 输入预填充日期

javascript - 操作对象 HTMLLIElement

javascript - React 超出最大更新深度 - 为什么只在子组件中?

javascript - 如何使用 JQuery 设置 onclick 监听器

javascript - 我想在当前视频结束后自动播放下一个视频

javascript - JS : Find object by field in a complex Parent-Child Array

Javascript 组合二进制标志