日期:2014-05-20  浏览次数:20453 次

请教个ImageButton的onclick事件.
做个注册页面.提交按纽用ImageButton
但验证表单用自写的JS.函数CheckForm()
这样我需要按下ImageButton后调用CheckForm()该JS函数.
为ImageButton加上ImageButton.Attributes.Add( "onclick ", "return   CheckForm(); ")

CheckForm(){
if(document.getElementById( "usrname ").value.length   ==   0){
alert( "username ");

return   false;
}
else{
return   true;
}

当我按下按钮后用户名为空时有alert效果.但return   false并没有起到作用.页面还是提交了.刷新了一次.这是用IE的效果.但用FF是有效的.真是好奇怪.我也弄不明白是怎么回事了.

------解决方案--------------------
Attributes.Add( "onclick ", "CheckForm(); ")
------解决方案--------------------
如果页面没有发生脚本错误,这样写在IE应该是没有问题的
试试在函数中加上event.cancelBubble = true;
------解决方案--------------------
你换种别的方式试试看呢~~~~
例如:换作button试试看,如果没毛病的话,就说明imgbutton不支持javascript的客户端事件