我的 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>
这是网站拒绝翻译的部分:
我做错了什么?
最佳答案
您可能会考虑仅使用更通用的选择器,例如 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/