我想在不刷新页面的情况下将表单的结果加载到div中。如果选择了选项,则应加载结果。通过选择该选项提交表单而不刷新页面,然后加载结果。这是代码,我将如何使用jquery
<form name="form" action="show.php" method="GET">
<select name="school" >
<option value="">School</option>
<option value="1">St.Peter</option>
<option value="2">JHS</option>
</select>
<input type="submit" name="Submit" value="Search" >
</form>
<?php
$s = $_GET['school'];
if($q && ($s =='1')){echo "St.peter H.S";}
elseif($q && ($s=='2')){echo "JHS";}
else echo "Enter something";
?>
答案 0 :(得分:1)
append()
就是你要找的!确保您要附加到正确的父级,并且您需要使用addClass()
来设置新创建的元素的样式!祝你好运。
答案 1 :(得分:1)
HTML:
<form name="form" action="show.php" method="GET">
<select name="school" >
<option value="">School</option>
<option value="1">St.Peter</option>
<option value="2">JHS</option>
</select>
<input type="submit" name="Submit" value="Search" >
</form>
<div id="result"></div>
PHP:
<?php
$s = $_GET['school'];
if($q && ($s =='1')){echo "St.peter H.S";}
elseif($q && ($s=='2')){echo "JHS";}
else echo "Enter something";
?>
jQuery的:
$(document).ready(function(){
$('select[name="school"]').change(function(){
$.get('show.php', {school : $(this).val()}, function(data){
// use .append(data), if you don't want to remove the previous content
$('#result').html(data);
});
});
});