前台页面:<select name='selCity' id='selCity'></select>
我想在后台取值将取出来值添加到selCity上
Page.RegisterStartupScript('',script);
string script="document.getElementById("selCity").options.add(new Option(取出来的值))";
这样不行...
大家有什么好的办法吗?注册客户端脚本 添取出来的值添加到selCity上
我想在后台取值将取出来值添加到selCity上
Page.RegisterStartupScript('',script);
string script="document.getElementById("selCity").options.add(new Option(取出来的值))";
这样不行...
大家有什么好的办法吗?注册客户端脚本 添取出来的值添加到selCity上
解决方案 »
- GridView 实现行上移下移
- XML 节点间插入的内容含有<>怎么弄啊!?
- 在gridview模板中添加了checkbox,通过选中checkbox拿到这一行的值
- Flash图片如何传参给.net
- CMMI3资料
- the status code returned from the server was:404
- c# 用鼠标拖动母板页改变宽度
- 关于UBB解释与Sql参数的问题
- mvc下自定义路由如何实现
- MS MVP 请进:如何調用在ASP.NET的C# Script中,用<object></object>定義的控件?
- GridView模板列不显示日期字段
- 将html、js代码过滤后,css代码怎么过滤?采集系统
我都是用这种方法,都可以啊,是不是浏览器的原因啊
1.判断select选项中 是否存在Value="paraValue"的Item
2.向select选项中 加入一个Item
3.从select选项中 删除一个Item
4.修改select选项中 value="paraValue"的text为"paraText"
5.设置select中text="paraText"的第一个Item为选中
6.设置select中value="paraValue"的Item为选中
7.得到select的当前选中项的value
8.得到select的当前选中项的text
9.得到select的当前选中项的Index
10.清空select的项
-------------------------------------------
//1.判断select选项中 是否存在Value="paraValue"的Item
function jsSelectIsExitItem(objSelect,objItemValue)
{
var isExit = false;
for(var i=0;i<objSelect.options.length;i++)
{
if(objSelect.options[i].value == objItemValue)
{
isExit = true;
break;
}
}
return isExit;
} //2.向select选项中 加入一个Item
function jsAddItemToSelect(objSelect,objItemText,objItemValue)
{
//判断是否存在
if(jsSelectIsExitItem(objSelect,objItemValue))
{
alert("该Item的Value值已经存在");
}
else
{
var varItem = new Option(objItemText,objItemValue);
// objSelect.options[objSelect.options.length] = varItem;
objSelect.options.add(varItem);
alert("成功加入");
}
}//3.从select选项中 删除一个Item
function jsRemoveItemFromSelect(objSelect,objItemValue)
{
//判断是否存在
if(jsSelectIsExitItem(objSelect,objItemValue))
{
for(var i=0;i<objSelect.options.length;i++)
{
if(objSelect.options[i].value == objItemValue)
{
objSelect.options.remove(i);
break;
}
}
alert("成功删除");
}
else
{
alert("该select中 不存在该项");
}
}//4.修改select选项中 value="paraValue"的text为"paraText"
function jsUpdateItemToSelect(objSelect,objItemText,objItemValue)
{
//判断是否存在
if(jsSelectIsExitItem(objSelect,objItemValue))
{
for(var i=0;i<objSelect.options.length;i++)
{
if(objSelect.options[i].value == objItemValue)
{
objSelect.options[i].text = objItemText;
break;
}
}
alert("成功修改");
}
else
{
alert("该select中 不存在该项");
}
}
//5.设置select中text="paraText"的第一个Item为选中
function jsSelectItemByValue(objSelect,objItemText)
{
//判断是否存在
var isExit = false;
for(var i=0;i<objSelect.options.length;i++)
{
if(objSelect.options[i].text == objItemText)
{
objSelect.options[i].selected = true;
isExit = true;
break;
}
}
//Show出结果
if(isExit)
{
alert("成功选中");
}
else
{
alert("该select中 不存在该项");
}
}//6.设置select中value="paraValue"的Item为选中
//document.all.objSelect.value = objItemValue;//7.得到select的当前选中项的value
//var currSelectValue = document.all.objSelect.value;//8.得到select的当前选中项的text
//var currSelectText = document.all.objSelect.options[document.all.objSelect.selectedIndex].text;//9.得到select的当前选中项的Index
//var currSelectIndex = document.all.objSelect.selectedIndex;//10.清空select的项
// document.all.objSelect.options.length = 0;
我不是要javascript方面的 是后台CS代码
string script="document.getElementById("selCity").options.add(new Option(取出来的值))";这样可以吗 还有没有其它注册客户端脚本的方法
abc.Items.Add(option);其中abc为前台<select></select>的id。
Page.RegisterStartupScript('',script);
不行?
报错吗?会不会是js执行时机的问题!我是用另外一种方法加载的,没问题!
方法:后台读到数据后,以数据的形式输出到前台,前台load事件里加载下拉控件
Page.RegisterStartupScript('',script);
这样可以吧!
var op = window.document.createElement("OPTION");
op.innerHTML = "-------";
op.value = "0";
slCity.appendChild(op);这样一定不会错,你的问题可能与W3C有关。