jQuery - フォームプラグインを使用して送信後にフォームをリセットする

StackOverflow https://stackoverflow.com/questions/6065468

質問

まず最初に言っておきますが、これは簡単そうに見えますが、非常に難しいと感じています。

PHP を使用する検索スクリプトを作成しました。結果を取得するには次のようになります。

search.php?term=alice&submit=Submit

定番のもの。。問題は、AJAX と PHP で SPI を使用しているため、ユーザーが検索する前にアクセスしていたページを失わないよう、ハッシュ値を保持しながら、結果を 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(); これ: jQueryを使用した多段階フォームのリセット 、しかし、これはどれも機能しません。これを行う方法を知っていれば助けてください。

役に立ちましたか?

解決

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

これにより、値を空白などの任意の値に設定できます。'';

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top