怎么将你的搜索框里面的值绑定,当你点击提交按钮进行搜索的时候,下拉框的值还是你之前搜索的时候选中的值????<select name="IsView" id="IsView" style="width:70px;">
<option value="1">显示</option>
<option value="0" >不显示</option>
</select>
<option value="1">显示</option>
<option value="0" >不显示</option>
</select>
提交给页面,程序处理的时候,如果有传这个值,处理下,在对模板对处理赋值过程中判断下就可以了,就有默认值了
<select name="sele">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</form>
echo $_POST['sele'];
<div id="searchResult"></div> ==>search.php
js
function fun(){
var isview=$('#IsView').val();
$.ajax({
url:"dosearch.php",//search.php处理文件,返回一些html语句
type:get,
dataType:html,
data:"IsView="+isview,
success:function(msg){
$('#searchResult').html(msg);
$('#IsView option[value='+isview+']').attr('selected',true);
}
});
}
<select name="test_name" style="width:155px;">
<option value="hotel_id" {{if $test_name=="hotel_id"}} selected {{/if}} >ID</option>
<option value="content" {{if $test_name=="content"}} selected {{/if}} >介绍</option>
<option value="source" {{if $test_name=="source"}} selected {{/if}} >备注</option>
</select>$test_name是在PHP中获取到的$test_name= get('test_name');
if(isset($_POST['IsView'])) {
$isView[$_POST['IsView']] = 'selected';
}
?>
<select name="IsView" id="IsView" style="width:70px;" value="0">
<option value="1" <?php echo $isView[1];?>>显示</option>
<option value="0" <?php echo $isView[0];?>>不显示</option>
</select>
$IsView=$_GET["IsView"];
echo "<select name='IsView' id='IsView' style='width:70px;'>";
if(($IsView==1)||($IsView==null)){
echo "<option value='1' selected='selected'>显示</option><option value="0" >不显示</option>";
}
else{
echo "<option value='1' >显示</option><option value='0' selected='selected' >不显示</option>";
}
echo "</select>";