我再写清楚一些,怕说得不清楚,按照正常执行的顺序是
<input type="button" name="ctl00$cph$SaveButton" value=" 保 存 " onclick="SaveButton(event);__doPostBack('ctl00$cph$SaveButton','')" id="ctl00_cph_SaveButton" />
<script type="text/javascript">
function SaveButton(e)
{
if(...)
{
//通过验证
}
else
{
//不通过者阻止提交
e.returnValue = false;
//这里无法阻止,他继续向下执行了__doPostBack('ctl00$cph$SaveButton','')
}
}
希望得到的是
<input type="button" name="ctl00$cph$SaveButton" value=" 保 存 " onclick="SaveButton(event);" id="ctl00_cph_SaveButton" />
经过jquery获得onclick属性内容,将__doPostBack('ctl00$cph$SaveButton','')暂存下来,再清空onclick属性,再写入SaveButton(event);命令。<script type="text/javascript">
function SaveButton(e)
{
//通过jquery获得onclick属性内容拆分等形式获得__doPostBack暂存入NetAct
var NetAct="__doPostBack('ctl00$cph$SaveButton','')";
if(...)
{
//通过验证
eval(NetAct);
}
else
{
//不通过者阻止提交
e.returnValue = false;
}
}
</script>
<input type="button" name="ctl00$cph$SaveButton" value=" 保 存 " onclick="SaveButton(event);__doPostBack('ctl00$cph$SaveButton','')" id="ctl00_cph_SaveButton" />
<script type="text/javascript">
function SaveButton(e)
{
if(...)
{
//通过验证
}
else
{
//不通过者阻止提交
e.returnValue = false;
//这里无法阻止,他继续向下执行了__doPostBack('ctl00$cph$SaveButton','')
}
}
希望得到的是
<input type="button" name="ctl00$cph$SaveButton" value=" 保 存 " onclick="SaveButton(event);" id="ctl00_cph_SaveButton" />
经过jquery获得onclick属性内容,将__doPostBack('ctl00$cph$SaveButton','')暂存下来,再清空onclick属性,再写入SaveButton(event);命令。<script type="text/javascript">
function SaveButton(e)
{
//通过jquery获得onclick属性内容拆分等形式获得__doPostBack暂存入NetAct
var NetAct="__doPostBack('ctl00$cph$SaveButton','')";
if(...)
{
//通过验证
eval(NetAct);
}
else
{
//不通过者阻止提交
e.returnValue = false;
}
}
</script>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货