你可以在后台用hiddenfield来保存每个选中的值 然后再前台js中来获取hiddenfield的值,在页面onload调用 function ShowAllIndex() { var hid1 = document.getElementById("HiddenField1"); var country = document.getElementById("ddlCountry"); var countryArray = document.getElementById("ddlCountry").getElementsByTagName("option"); var province = document.getElementById("ddlProvince"); var provincetxt = document.getElementById("txtProvince"); var questiontxt= document.getElementById("txtQuestions"); var lblProvince= document.getElementById("Label33"); var p; for(p=0;p<countryArray.length;p++) {
例如:select下拉框有1,2,3,4,5,(动态生成的,来源于数据库)默认为1,假设我选择3后,提交,页面返回后下拉框显示是1,而不是3,现在要实现显示3的效果,不知道我现在表达清楚了没有,要还没有的话,那就是我表达能力的问题了
然后再前台js中来获取hiddenfield的值,在页面onload调用 function ShowAllIndex()
{
var hid1 = document.getElementById("HiddenField1");
var country = document.getElementById("ddlCountry");
var countryArray = document.getElementById("ddlCountry").getElementsByTagName("option");
var province = document.getElementById("ddlProvince");
var provincetxt = document.getElementById("txtProvince");
var questiontxt= document.getElementById("txtQuestions");
var lblProvince= document.getElementById("Label33");
var p;
for(p=0;p<countryArray.length;p++)
{
if(countryArray[p].value!=null && countryArray[p].value==hid1)
{
countryArray[p].selected=true;
}
}
第二种,根本不考虑什么通过asp.net完成“提交,页面返回”的功能,完全使用自己的脚本代码、异步ajax来实现交互。