我有三页new.html
,somepage.html
和someotherpage.html
new.html
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
$('#nav a').click(function(e) {
e.preventDefault();
$('#content').load($(this).attr('href'));
});
});
</script>
<div id="nav"><a href="somepage.html">Some page</a></div>
<div id="content">show the stuff</div>
点击somepage.html
链接时,它会显示在div
,其ID为content
。
somepage.html
<form id="form" action="someotherpage.html" method="post">
<input type="submit" value="test"/>
</form>
表单的操作转到新页面,而我希望它只在实际表单所在的div
内。
答案 0 :(得分:0)
您必须做与第一页非常相似的事情,在表单的兄弟中加载someotherpage.html
:
somepage.html :
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
<script>
$('#form').submit(function(e) {
e.preventDefault();
$('#target').load($(this).attr('action'));
});
</script>
<div id="formWrapper">
<form id="form" action="someotherpage.html" method="post">
<input type="submit" value="test"/>
</form>
<div id="target"></div>
</div>