如果邮件已成功发送或发生错误,我正尝试设置警告消息。
当我运行并点击"发送邮件"这是以下错误;我的html页面中的按钮。
错误:Microsoft JScript运行时错误:无法获取值 property' addClass&#39 ;: object is null或undefined
这是我的PHP代码段:
if(@mail($to,$subject,$message,$header)) $send = true; else $send = false;
if(isset($_POST['email'])){
if ($send)
{
echo '<script language="javascript">';
echo 'alert("Mail has been Sent Successfully")';
echo '</script>';
exit;
}
else
{
echo '<script language="javascript">';
echo 'alert("ERROR")';
echo '</script>';
exit;
}
这是我的jQuery代码段:
function tfuse_custom_form(){
var my_error;
var url = jQuery("input[name=temp_url]").attr('value');
jQuery("#send").bind("click", function(){
my_error = false;
jQuery(".ajax_form input, .ajax_form textarea, .ajax_form radio, .ajax_form select").each(function(i)
{
var surrounding_element = jQuery(this);
var value = jQuery(this).attr("value");
var check_for = jQuery(this).attr("id");
var required = jQuery(this).hasClass("required");
if(check_for == "email")
{
surrounding_element.removeClass("error valid");
baseclases = surrounding_element.attr("class");
if(!value.match(/^\w[\w|\.|\-]+@\w[\w|\.|\-]+\.[a-zA-Z]{2,4}$/))
{
surrounding_element.attr("class",baseclases).addClass("error");
my_error = true;
}
else
{
surrounding_element.attr("class",baseclases).addClass("valid");
}
}
if(check_for == "message")
{
surrounding_element.removeClass("error valid");
baseclases = surrounding_element.attr("class");
if(value == "" || value == "Write your message...")
{
surrounding_element.attr("class",baseclases).addClass("error");
my_error = true;
}
else
{
surrounding_element.attr("class",baseclases).addClass("valid");
}
}
if(required && check_for != "email" && check_for != "message")
{
surrounding_element.removeClass("error valid");
baseclases = surrounding_element.attr("class");
if(value == "")
{
surrounding_element.attr("class",baseclases).addClass("error");
my_error = true;
}
else
{
surrounding_element.attr("class",baseclases).addClass("valid");
}
}
}
答案 0 :(得分:0)
首先比较这段代码,然后只需要在php中jquery就可以替换它 在php文件中添加此代码。
1)。
<?php echo '<script language="javascript">
alert("Mail has been Sent Successfully");
</script>';
?>
2)。
if ($send)
{
echo '<script language="javascript">
alert("Mail has been Sent Successfully");
</script>';
exit;
}
else
{
echo '<script language="javascript">
alert("ERROR")'
</script>';
exit;
}