jQuery - 使用表单插件提交后重置表单
首先我要说的是,这可能看起来很简单,但我发现它非常困难。
我制作了一个使用 PHP 的搜索脚本并获取结果,看起来像这样
search.php?term=alice&submit=Submit
标准的东西..问题是,我使用带有 AJAX 和 PHP 的 SPI因此我的结果必须动态加载到 div 中,同时仍然保留哈希值,以免丢失用户在搜索之前访问过的页面。
jQuery.history.js 是我用于后退按钮支持的插件,它要求链接如下所示:
这将加载'home.html' 到名为 pageContent 的 div 中。据我所知,除非你开发一个小技巧,否则无法调用 php 文件,
这是我的搜索表单的 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>
表单如下:
<form id="search1" action="search.php" method="post">
<input id="query" type="text" name="term" />
<input type="submit" name="submit" value="Submit" />
</form>
我的问题是这样的: 我试过 this.form.reset();
这个:重置带有 jQuery 的多阶段表单,但这些都不起作用。如果您知道这样做的方法,请帮助我..
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
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.
jQuery.history.js is the plugin i use for back button support, which requires links to be like such:
<a href="#home">Home Page</a>
this would load 'home.html' into a div named pageContent. as far as i know theres no way to call php files unless you develop a little hack, which i have,
here is my JavaScript/jQuery for my search form:
<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: Resetting a multi-stage form with jQuery , yet none of this works. please help me if you know a way of doing this..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有了这个,你可以将你的值设置为你想要的任何值,例如空白:'';
with this u can set your value to whatever you want, like blank: '';