1

index.htmlとexternal.htmlの2つのページがあります。index.htmlには2つのテキストフィールドがあります。これらのテキストフィールドにテキストを挿入してボタンをクリックすると、external.htmlページに移動します。このexternal.htmlページには、index.htmlにリンクするボタンが1つあります。そのボタンをクリックすると、index.htmlに移動します。

ここで問題となるのは、external.htmlからindex.htmlに移動しても、テキストフィールドが以前の値のままになることです。index.htmlページにアクセスしたときに、以前の値をクリアしたかったのです。その方法を教えてください。

index.html

<section id="firstpage" data-role="page">
    <header data-role="header" data-position="fixed">      
        <h1>First</h1>
    </header>

    <div data-role="content" >

    <script type="text/javascript" >
        $( function(){
            $( '#name_field' ).val( "" );

        });


        $(document).ready(function () {
          $('.clearme').focus(function() {
            $(this).val("");
          });
        });

    </script>


    <label for="name" >Name:</label>
    <input type="text" name="name" id="name_field" value="" class="clearme" placeholder="Enter Name"/>

    <label for="email">Email:</label>
    <input type="email" name="email" id="email_field" value="" placeholder="Enter Email Id" />

    <input type="submit" id="button" value="External Page" data-theme="b"  onclick="_gotopage( 'http://localhost/test/external.html' );"/>
    </div>

    <footer data-role="footer" data-theme="d" >    

    </footer>   
</section>

external.html

<section id="secondpage" data-role="page">
    <header data-role="header" data-position="fixed">      
        <h1>External</h1>
    </header>

    <div data-role="content" >

    <script type="text/javascript" >


    </script>
           <input type="submit" id="comment_enter_button" value="Index Page" data-theme="b"  onclick="_gotopage( 'http://localhost/test/index.html' );"/>
    </div>

    <footer data-role="footer" data-theme="d" >    

    </footer>   
</section>

script.js

function gotopage( gotopage )
{ 
  $.mobile.changePage($( gotopage ), { transition: "slide"});
}



function _gotopage( page )
{
  $.mobile.changePage( page);
}
4

1 に答える 1

3

このようなものを探していますか?:

$(document).on('pageshow', function () {
    $('.clearme').val("");
});
于 2012-09-26T16:36:17.693 に答える