我有两页index.html和external.html.In index.html我有两个文本字段。在这些文本字段中插入一些文本并单击按钮我将转到external.html页面。此external.html页面有一个链接到index.html的按钮。当点击该按钮时,它会将我移动到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);
}
答案 0 :(得分:3)
这是你想要的东西吗?:
$(document).on('pageshow', function () {
$('.clearme').val("");
});