有几个问题,标题是.html(
)。 下面是一部法典,将“电子邮件地址”的文字箱输入值改为“如果它们没有输入任何内容,则将“电子邮件地址”重新贴在模版上。
I m using jquery .html(
> with .post(
to phpmailer to Update the contained div with "Sending. >. “成功发送”等。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#emailaddressinput").focus(function(){
if ($(this).val() == Enter email address ) {
$(this).val( );
}
});
$("#emailaddressinput").blur(function(){
if (!$.trim($(this).val())) {
$(this).val( Enter email address );
}
});
});
</script>
Here s the code that POSTS to phpmailer. On success the response is true
. However, when it fails, it uses dotimeout.js to delay 3 seconds and then uses jquery .html
to put the original form back in place. When it does this, the above code doesn t work anymore. At the bottom is my original html.
<script src="lib/dotimeout.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$( #emailbutton ).click(function(e) {
e.preventDefault();
var email = $( #emailaddressinput ).val();
//write sending... or something
$( #emailinputcontainer ).html( Sending, please wait. );
var generated_coupon_id = 2 ;
var dataString = email= + email + &generated_coupon_id= + generated_coupon_id;
$.post( send.php , dataString, function(data){
//do stuff
if(data== true ){
//say "message sent!"
$( #emailinputcontainer ).html( Your coupon has been emailed! );
} else {
//say error
$( #emailinputcontainer ).html( There was an error. Please try again. );
$.doTimeout(3000,function() {
$( #emailinputcontainer ).html( <input id="emailaddressinput" type="text" value="Enter email address" /><a id="emailbutton" href="#" style="margin: 0 !important;"><span class="buttontext" >Email coupon</span></a> );
});
}
});
});
});
</script>
The original html of the form:
<div id="emailinputcontainer">
<input id="emailaddressinput" type="text" value="Enter email address" /><a id="emailbutton" href="#" style="margin: 0 !important;"><span class="buttontext" >Email coupon</span></a>
</div>
当电子邮件失败时,我如何在本页顶上看到我的原始文字,我又使用<条码>.html(<>/条码>)重新载录原始内容。
EDIT:实际上,我进一步推敲现在的<代码>。