簡體   English   中英

jQuery - 使用表單插件提交后重置表單

[英]jQuery - reset form after submit w/ form plugin

首先讓我說它可能看起來很簡單,但我發現它非常困難。

我制作了一個使用 PHP 的搜索腳本並獲取結果如下所示

search.php?term=alice&submit=Submit

標准的東西.. 問題是,我將 SPI 與 AJAX 和 PHP 一起使用,因此我的結果必須動態加載到 div 中,同時仍保留哈希值,以免丟失用戶在搜索之前訪問過的頁面。

jQuery.history.js 是我用於后退按鈕支持的插件,它要求鏈接像這樣:

<a href="#home">Home Page</a>

這會將“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(); this: 使用 jQuery 重置多階段表單,但這些都不起作用。 如果您知道這樣做的方法,請幫助我。

$('#query').val(DefaultValue);

有了這個,您可以將您的值設置為您想要的任何值,例如空白:'';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM