代码如下:
<asp:DropDownList ID="drpTest" AutoPostBack="true" runat="Server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
</asp:DropDownList>
<input type="button" value="MyTest" onclick="MyTest()" />
<script type="text/javascript">
var drpTest = document.getElementById("<%= drpTest.ClientID %>");
function MyTest()
{
if (drpTest.selectedIndex == 0)
drpTest.options[1].selected = true;
else
drpTest.options[0].selected = true;
}
</script>
我的意思是在javascript中改变drpTest的选中项时,引起drpTest的自动回发(AutoPostBack设置为了“True”),但是始终只有鼠标点选不同选项时,才会回发,点MyTest按钮,drpTest的选项是变了,但是却没有回发现象产生。请问要如何写才能起到作用??
<asp:DropDownList ID="drpTest" AutoPostBack="true" runat="Server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
</asp:DropDownList>
<input type="button" value="MyTest" onclick="MyTest()" />
<script type="text/javascript">
var drpTest = document.getElementById("<%= drpTest.ClientID %>");
function MyTest()
{
if (drpTest.selectedIndex == 0)
drpTest.options[1].selected = true;
else
drpTest.options[0].selected = true;
}
</script>
我的意思是在javascript中改变drpTest的选中项时,引起drpTest的自动回发(AutoPostBack设置为了“True”),但是始终只有鼠标点选不同选项时,才会回发,点MyTest按钮,drpTest的选项是变了,但是却没有回发现象产生。请问要如何写才能起到作用??
解决方案 »
- winform中怎样使DataGridView的某一列可以添加两个Button控件
- 正则表达式学习
- 请教,C# DataGridView百分比
- 我想把窗体的左上角的关闭事件自己写,为了实现关闭本窗体时可以一起关闭其他窗体
- 【All】大家看看,这个效果怎么实现?
- 在建立与服务器的连接时出错,在连接到sql server2005时,在默认设置下sql server不允许进行远程连接可能导致此失败
- [求助]在子窗体中如何获取父窗体HTML控件的值
- 求C#调用C++DLL的例子
- 好像是超级难题,却又看似简单的问题。我已放出80分在.net上,无果,再放100分求解!!
- 线程在sleep情况下如何让程序能继续运行
- C#网页页面内容生成excel怎么弄?
- 求助:控件焦点的问题
var drpTest = document.getElementById(" <%= drpTest.ClientID %>");
function MyTest()
{
if (drpTest.selectedIndex == 0)
drpTest.options[1].selected = true;
else
drpTest.options[0].selected = true; document.form1.submit();
}
</script>
drpTest.options[1].selected = true;
else
drpTest.options[0].selected = true; =>if (drpTest.selectedIndex == 0)
drpTest.options[1].selected = true;
else
drpTest.options[0].selected = true;
__doPostBack('<%= drpTest.ClientID %>','');
明显你的例子不满足先要条件,所以没有产生回发
3楼的代码就是自行回发了
调用后台方法
_doPostBack('drpTest','');
{
var drpTest = document.getElementById("drpTest1");
if (drpTest.selectedIndex == 0)
drpTest.options[1].selected = true;
else
drpTest.options[0].selected = true;
alert(drpTest.options[0].value) ;
drpTest.onchange();
}