![](/img/trans.png)
[英]blur() and keypress() not working on JQuery with replacewith()
[英]blur() and focus() not working on jQuery with replaceWith()
我使用的是jQuery表单,当您单击某个字段时,它将显示有关在该字段中做什么的提示。
标签。 使用我现在拥有的代码,它将对第一个元素起作用,但是之后,如果我尝试单击另一个,它将不会覆盖以前的更改。 我尝试在模糊时使用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>");
});
});
我尝试与第一个链接,以查看是否有任何区别,但是没有。
不要使用replaceWith()尝试使用html()之类的方法,
$("#mail").focus(function() {
$("#helpP").html("<p>This e-mail address will be used as your login and for receiving special offers from Volga</p>");
}).blur(function(){
$("#helpP").empty();// use # before id selector
});
从replaceWith()文档中,
说明:用提供的新内容替换匹配元素集中的每个元素,并返回被删除的元素集。
而且您的elements
将被p elements
replaced
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.