【发布时间】:2013-12-03 08:56:07
【问题描述】:
我正在使用 jQuery 制作一个表单,当您单击某个字段时,它会在一个
中显示有关在该字段中做什么的提示标签。使用我现在拥有的代码,它将适用于第一个元素,但之后如果我尝试单击另一个元素,它将不会覆盖以前的更改。我尝试在 blur 上使用 empty() ,但这不会清除任何内容,而且我不知道这是否真的能解决问题。如果有人能给我任何关于这里有什么问题的见解,我将不胜感激!
#helpP 是我要在其中更改文本的段落。其他 ID 只是表单字段。
$(document).ready(function () {
$("#mail").focus(function() {
$("#helpP").replaceWith("<p>This e-mail address will be used as your login and for receiving special offers from Volga</p>");
}).blur(function(){
$("helpP").empty();
});
$("#confirmEmail").focus(function() {
$("#helpP").replaceWith("<p>Confirm your e-mail</p>");
});
$("#confirmEmail").blur(function() {
$("#helpP").empty();
});
$("#passwordReg").focus(function() {
$("#helpP").replaceWith("<p>Passwords can only have letters and numbers and are case sensitive.</p>");
});
$("#passwordRegConfirm").focus(function() {
$("#helpP").replaceWith("<p>Enter the same password again to ensure accuracy</p>");
});
});
我尝试与第一个链接,看看是否有任何不同,但没有。
【问题讨论】:
-
您是否尝试过将其替换为 html() 而不是 replaceWith()?
标签: jquery forms focus blur replacewith