[英]jQuery - reset form after submit w/ form plugin
let me start by saying it may look simple but im finding it extremely difficult.首先让我说它可能看起来很简单,但我发现它非常困难。
ive made a search script that uses PHP and to fetch a result would look like this我制作了一个使用 PHP 的搜索脚本并获取结果如下所示
search.php?term=alice&submit=Submit
Standard stuff.. problem is, i use an SPI with AJAX and PHP so my results would have to load dynamically into a div, whilst still keeping the hash value, as not to lose the page the user had visited previous to searching.标准的东西.. 问题是,我将 SPI 与 AJAX 和 PHP 一起使用,因此我的结果必须动态加载到 div 中,同时仍保留哈希值,以免丢失用户在搜索之前访问过的页面。
jQuery.history.js is the plugin i use for back button support, which requires links to be like such: jQuery.history.js 是我用于后退按钮支持的插件,它要求链接像这样:
<a href="#home">Home Page</a>
this would load 'home.html' into a div named pageContent.这会将“home.html”加载到名为 pageContent 的 div 中。 as far as i know theres no way to call php files unless you develop a little hack, which i have,
据我所知没有办法调用 php 文件,除非你开发了一个我有的小技巧,
here is my JavaScript/jQuery for my search form:这是我的搜索表单的 JavaScript/jQuery:
<script language="JavaScript">
$(document).ready(function() {
// bind form using ajaxForm
$('#search1').ajaxForm({
// target identifies the element(s) to update with the server response
target: '#pageContent',
// success identifies the function to invoke when the server response
success: function() {
$('#pageContent');
var hash = '#search.php?term='+($('#query').val()+'&submit=Submit').replace(/ /g, '+');
var stripped = hash.replace(/(<([^>]+)>)/ig,"");
update(window.location.hash = stripped);
}
});
});
</script>
Heres the form:表格如下:
<form id="search1" action="search.php" method="post">
<input id="query" type="text" name="term" />
<input type="submit" name="submit" value="Submit" />
</form>
My problem is this: ive tried this.form.reset();
我的问题是:我试过
this.form.reset();
this: Resetting a multi-stage form with jQuery , yet none of this works. this: 使用 jQuery 重置多阶段表单,但这些都不起作用。 please help me if you know a way of doing this..
如果您知道这样做的方法,请帮助我。
$('#query').val(DefaultValue);
有了这个,您可以将您的值设置为您想要的任何值,例如空白:'';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.