询问者
如何用脚本点击radiobutton的onclick事件?

常规讨论
-
radiobutton的onclick事件用如下方法加入:
rdbutton.Attributes.Add("onclick", "_dosth(a, b, c);");
在后台代码中想注册js调用该事件:
string script = @"document.getElementById('"+rdbutton.ClientID + @"').click(); ";
ScriptManager.RegisterStartupScript (this, typeof(Page), "WariningScript", script, true);在输出页面中HTML代码如下:
<input id="ctl00_cphPage_ctl00_Handle1_gvHandlerList_ctl03_ctl00" type="radio" name="ctl00$cphPage$ctl00$Handle1$gvHandlerList$ctl03$ctl00" value="165" checked="checked" onclick="_dosth(a, b, c);"/>
document.getElementById('ctl00_cphPage_ctl00_Handle1_gvHandlerList_ctl03_ctl00').click();
问题是:脚本_dosth(a, b, c);并没有被执行。。。
是不是这个写法有问题??该怎么写?
- 已更改类型 KeFang Chen 2010年4月2日 2:56
全部回复
-
感谢你的关注,后来代码可以运行了,至于为什么,我也不知道,:) 为什么不直接调用脚本的原因是,我这里简化了脚本的写法,实际应用中_dosth(a, b, c); 的a,b,c是一些变量,在别的地方生成。。我的目的是调用click事件,而不用hardcode具体的js方法。。不知道我说清楚没有。。。你的流程是:
用户点击按钮就运行"_dosth(a, b, c);"
其实,你现想通过脚本来点击这个按钮,从而触发 _dosth(a, b, c); 事件。
为什么不在脚本中直接调用 _dosth(a, b, c); 呢?
Extension of New Channels 积淀孕育创新,智慧创造价值