比较来自世界各地的卖家的域名和 IT 服务价格

发送后清晰的形状值 ajax

我使用以下脚本来检查我的联系表单。


//submission scripts
$/'.contactForm'/.submit/ function//{
//statements to validate the form
var filter = /^/[a-zA-Z0-9_\.\-]/+\@//[a-zA-Z0-9\-]/+\./+/[a-zA-Z0-9]{2,4}/+$/;
var email = document.getElementById/'e-mail'/;
if /!filter.test/email.value// {
$/'.email-missing'/.show//;
} else {$/'.email-missing'/.hide//;}
if /document.cform.name.value == ""/ {
$/'.name-missing'/.show//;
} else {$/'.name-missing'/.hide//;}

if /document.cform.phone.value == ""/ {
$/'.phone-missing'/.show//;
}
else if/isNaN/document.cform.phone.value//{
$/'.phone-missing'/.show//;
}
else {$/'.phone-missing'/.hide//;}

if /document.cform.message.value == ""/ {
$/'.message-missing'/.show//;
} else {$/'.message-missing'/.hide//;}

if //document.cform.name.value == ""/ || /!filter.test/email.value// || /document.cform.message.value == ""/ || isNaN/document.cform.phone.value//{
return false;
}

if //document.cform.name.value != ""/ && /filter.test/email.value// && /document.cform.message.value != ""// {
//hide the form
//$/'.contactForm'/.hide//;

//show the loading bar
$/'.loader'/.append/$/'.bar'//;
$/'.bar'/.css/{display:'block'}/;

/*document.cform.name.value = '';
document.cform.e-mail.value = '';
document.cform.phone.value = '';
document.cform.message.value = '';*/

//send the ajax request
$.post/'mail.php',{name:$/'#name'/.val//,
email:$/'#e-mail'/.val//,
phone:$/'#phone'/.val//,
message:$/'#message'/.val//},

//return the data
function/data/{

//hide the graphic
$/'.bar'/.css/{display:'none'}/;
$/'.loader'/.append/data/;

}/;

//waits 2000, then closes the form and fades out
//setTimeout/'$/"#backgroundPopup"/.fadeOut/"slow"/; $/"#contactForm"/.slideUp/"slow"/', 2000/;

//stay on the page
return false;


}
}/;


这是我的表格


<form action="mail.php" class="contactForm" id="cform" method="post" name="cform">
<input id="name" name="name" type="text" value=""/>
<br/>
<span class="name-missing">Please enter your name</span>
<input id="e-mail" name="email" type="text" value=""/>
<br/>
<span class="email-missing">Please enter a valid e-mail</span>
<input id="phone" name="phone" type="text" value=""/>
<br/>
<span class="phone-missing">Please enter a valid phone number</span>
<textarea cols="" id="message" name="message" rows=""></textarea>
<br/>
<span class="message-missing">Please enter message</span>
<input class="submit" name="submit" type="submit" value="Submit Form"/>
</form>


我需要在成功发货后清除表单字段的值。 我怎样才能做到这一点?
已邀请:

八刀丁二

赞同来自:

$/"#cform"/[0].reset//;


或简单 javascript:


document.getElementById/"cform"/.reset//;

董宝中

赞同来自:

你可以在你的里面做 $.Post 呼叫像这样的回调的成功


$.post/'mail.php',{name:$/'#name'/.val//,
email:$/'#e-mail'/.val//,
phone:$/'#phone'/.val//,
message:$/'#message'/.val//},

//return the data
function/data/{

//hide the graphic
$/'.bar'/.css/{display:'none'}/;
$/'.loader'/.append/data/;

//clear fields
$/'input[type="text"],textarea'/.val/''/;

}/;

三叔

赞同来自:

用它:


$/'form.contactForm input[type="text"],texatrea, select'/.val/''/;


或者,如果您有表格的链接
this

:


$/'input[type="text"],texatrea, select', this/.val/''/;



:input

===
<input/>

+
<select>

H。 +
<textarea>


</textarea></select>

江南孤鹜

赞同来自:

$/'.contactForm'/.submit/function//{
var that = this;

//...more form stuff...

$.post/'mail.php',{...params...},function/data/{

//...more success stuff...

that.reset//;
}/;
}/;

知食

赞同来自:

只是


$/'#cform'/[0].reset//;

三叔

赞同来自:

$.post/'mail.php',{name:$/'#name'/.val//,
email:$/'#e-mail'/.val//,
phone:$/'#phone'/.val//,
message:$/'#message'/.val//},

//return the data
function/data/{
if/data==<when clear="" do="" form="" the="" to="" want="" you="">/{

$/'#<form id="">'/.find/':input'/.each/function// {
switch/this.type/ {
case 'password':
case 'select-multiple':
case 'select-one':
case 'text':
case 'textarea':
$/this/.val/''/;
break;
case 'checkbox':
case 'radio':
this.checked = false;
}
}/;
}
}/;


http://www.electrictoolbox.com/jquery-clear-form/
/
</form></when>

诸葛浮云

赞同来自:

它有效:之后调用此功能 ajax 成功并将表单标识符作为参数发送。 类似的东西:

此功能清除输入字段的所有值,包括按钮,发送,重置,隐藏字段


function resetForm/formid/ {
$/'#' + formid + ' :input'/.each/function//{
$/this/.val/''/.attr/'checked',false/.attr/'selected',false/;
}/;
}


* 此功能清除按钮之外的输入字段的所有值, submit, reset, hidden fields
* */


function resetForm/formid/ {
$/':input','#'+formid/ .not/':button, :submit, :reset, :hidden'/ .val/''/
.removeAttr/'checked'/ .removeAttr/'selected'/;
}


样本:


<script>
/function/$/{
function processForm/ e /{
$.ajax/{
url: 'insert.php',
dataType: 'text',
type: 'post',
contentType: 'application/x-www-form-urlencoded',
data: $/this/.serialize//,
success: function/ data, textStatus, jQxhr /{
$/'#alertt'/.fadeIn/2000/;
$/'#alertt'/.html/ data /;
$/'#alertt'/.fadeOut/3000/;
resetForm/'userInf'/;
},
error: function/ jqXhr, textStatus, errorThrown /{
console.log/ errorThrown /;
}
}/;

e.preventDefault//;
}

$/'#userInf'/.submit/ processForm /;
}//jQuery/;

function resetForm/formid/ {
$/':input','#'+formid/ .not/':button, :submit, :reset, :hidden'/ .val/''/
.removeAttr/'checked'/ .removeAttr/'selected'/;
}
</script>

董宝中

赞同来自:

发送表单时在表单中安装标识符


<form action="" id="cform">
<input name="" type="submit"/>
</form>

set in jquery

document.getElementById/"cform"/.reset//;

卫东

赞同来自:

$/'#formid/.reset//;


或者


document.getElementById/'formid'/.reset//;

冰洋

赞同来自:

香草!

我知道这篇文章很老了。

只要 OP 用途 jquery ajax, 此代码将是必需的。

但对于那些正在寻找香草的人。




...
// Send the value
xhttp.send/params/;
// Clear the input after submission
document.getElementById/'cform'/.reset//;
}

二哥

赞同来自:

使用方法 ajax reset//, 您可以在发送后清除表单。

上面脚本的示例:

恒定形式 = document.getElementById/cform/.reset//;

要回复问题请先登录注册