首先要保证按钮是BUTTON,并且按钮事件设置firePartialAction。

public class CuxXXXXPGCO
extends OAControllerImpl
{
public static final String RCS_ID = "$Header$";
public static final boolean RCS_ID_RECORDED =
VersionInfo.recordClassVersion(RCS_ID, "%packagename%");

private String disableButtonMultiClickByIdJs ="function submitApprove(evt) { \n" +
" console.log('function start evt ' + evt);\n" +
" disabledButton(); \n" +
" console.log('evt execute');\n" +
" MyPeriodicalExecuter(); \n" +
" } \n" +
" function disabledButton(){ \n" +
" var text = document.getElementById(\"Test\");\n" + //此处的ID改为你要在5秒后启用的ID
" console.log('Test');\n" +
" text.disabled=true;\n" +
" } \n" +
" \n" +
" function MyPeriodicalExecuter(){ \n" +
" succ.loop=0; \n" +
" console.log('111');\n" +
" sh=setInterval(succ,1000); \n" +
" console.log('777');\n" +
" } \n" +
" \n" +
" function succ(){ \n" +
" console.log('222');\n" +
" with(arguments.callee){ \n" +
" console.log('333');\n" +
" console.log('loop = '+loop);\n" +
" loop++;\n" +
" //obj.value=str+\"(\"+(loop++)+\"/15)retry\"; \n" +
" if (loop > 5 ){ \n" +
" console.log('444');\n" +
" enabledButton(); \n" +
" console.log('555');\n" +
" clearInterval(sh); \n" +
" console.log('666');\n" +
" return; \n" +
" } \n" +
" } \n" +
" } \n" +
" \n" +
" function enabledButton(){ \n" +
" console.log('enabledButton evt End');\n" +
" var text = document.getElementById(\"Test\");\n" + //此处的ID改为你要在5秒后启用的ID
" console.log('text getElementById FinSign');\n" +
" text.disabled=false; \n" +
" }";

/**
* Layout and page setup logic for a region.
* @param pageContext the current OA page context
* @param webBean the web bean corresponding to the region
*/
public void processRequest(OAPageContext pageContext,
OAWebBean webBean)
{
super.processRequest(pageContext, webBean); pageContext.removeJavaScriptFunction("submitApprove");
// pageContext.putJavaScriptFunction("submitApprove", disableButtonMultiClickJs);
pageContext.putJavaScriptFunction("submitApprove", disableButtonMultiClickByIdJs);
String submitJs = "javascript:submitApprove(this.id);"; OAButtonBean button = (OAButtonBean)webBean.findChildRecursive("Test"); button.setAttributeValue(OAWebBeanConstants.ON_CLICK_ATTR,submitJs); //两个方法是一致的
// button.setOnClick(submitJs); //两个方法是一致的     //your other business logic ...
  }

/**
* Procedure to handle form submissions for form elements in
* a region.
* @param pageContext the current OA page context
* @param webBean the web bean corresponding to the region
*/
public void processFormRequest(OAPageContext pageContext,
OAWebBean webBean)
  {

  //your business logic

}
}

此方法仍然有一个可以优化的地方,js代码中getElementById中的id值是写死了的,可以其实通过传入button.id的形式,使用全局变量,使得查找button通过id的方式,代码如下

1. 要清楚在哪个地方声明定义的是 全局变量 还是 局部变量 。
2. 全局变量所带来的 bug 问题非常多,可能很偶然的把代码放到其他页面里,把新页面的同名变量给覆盖,造成隐藏的 bug 。最好尽量少用全局变量。

所以这里要使用全局变量还是局部变量就见仁见智了

(不过经过测试,在IE浏览器中,此段代码不能正常运行,导致Test Button中的业务逻辑不能正常执行,猜测可能是Console.log引起的,建议删除Console.log,不然IE浏览器不能正确运行。)

(IE不支持console.log,会阻止程序的进一步执行)

public class CuxXXXXPGCO
extends OAControllerImpl
{
public static final String RCS_ID = "$Header$";
public static final boolean RCS_ID_RECORDED =
VersionInfo.recordClassVersion(RCS_ID, "%packagename%");

//禁用按钮在5秒内连续点击
private String disableButtonMultiClickByIdJs ="var buttonId ='buttonId';\n" + //JavaScript全局变量

//全局变量所带来的 bug 问题非常多,可能很偶然的把代码放到其他页面里,把新页面的同名变量给覆盖,造成隐藏的 bug 。最好尽量少用全局变量。
"function submitApprove(evt) { \n" +
" buttonId = evt;\n" +
" disabledButton(buttonId); \n" +
" MyPeriodicalExecuter(); \n" +
" } \n" +
" function disabledButton(){ \n" +
" var text = document.getElementById(buttonId);\n" + //此处的ID改为你要在5秒后启用的ID
" text.disabled=true;\n" +
" } \n" +
" \n" +
" function MyPeriodicalExecuter(){ \n" +
" succ.loop=0; \n" +
" sh=setInterval(succ,1000); \n" +
" } \n" +
" \n" +
" function succ(){ \n" +
" with(arguments.callee){ \n" +
" loop++;\n" +
" if (loop > 5 ){ \n" +
" enabledButton(); \n" +
" clearInterval(sh); \n" +
" return; \n" +
" } \n" +
" } \n" +
" } \n" +
" \n" +
" function enabledButton(){ \n" +
" var text = document.getElementById(buttonId);\n" + //此处的ID改为你要在5秒后启用的ID
" text.disabled=false; \n" +
" return; \n" +
" }";

/**
* Layout and page setup logic for a region.
* @param pageContext the current OA page context
* @param webBean the web bean corresponding to the region
*/
public void processRequest(OAPageContext pageContext,
OAWebBean webBean)
{
super.processRequest(pageContext, webBean);

pageContext.removeJavaScriptFunction("submitApprove");
// pageContext.putJavaScriptFunction("submitApprove", disableButtonMultiClickJs);
pageContext.putJavaScriptFunction("submitApprove", disableButtonMultiClickByIdJs);
String submitJs = "javascript:submitApprove(this.id);";

OAButtonBean button = (OAButtonBean)webBean.findChildRecursive("Test");

button.setAttributeValue(OAWebBeanConstants.ON_CLICK_ATTR,submitJs); //与下面的等价
// button.setOnClick(submitJs);//与上面的等价

//

}

/**
* Procedure to handle form submissions for form elements in
* a region.
* @param pageContext the current OA page context
* @param webBean the web bean corresponding to the region
*/
public void processFormRequest(OAPageContext pageContext,
OAWebBean webBean)
{

//your logic

}

}

同时还有一个未解决的bug,如果在按钮执行之后发生了跳转,通过控制台可以看到loop会一直递增,直到发生下一个事件时终止。

Chrome浏览器在开启了F12日志诊断功能之后,可以看到console.log输出的日志如下

OAF 使用 javascript 使某个按钮在5秒内不能重复点击的更多相关文章

  1. 使用js使某个按钮在5秒内不能重复点击

    <head> <!--参考:http://illy.iteye.com/blog/1534276 --> <!-- http://y.dobit.top/Detail/1 ...

  2. VS2010 使用时选择代码或双击时出错,点击窗口按钮后VS自动重启问题

    VS2010 使用时选择代码或双击时出错崩溃,点击窗口按钮后VS自动重启问题 下载补丁,打上补丁之后,重启电脑,解决了问题. WindowsXP的下载地址:Windows XP 更新程序 (KB971 ...

  3. 关于javascript中限定时间内防止按钮重复点击的思路

    前面的话 有一天心血来潮,1分钟内重复点击了多次博客园首页的刷新博文列表的刷新按钮.果不其然,ip当时就被禁用了.后来,重启自己的路由器,重新获取ip才可以访问博客园主页.那么,设置一个限定时间内(比 ...

  4. Qt和JavaScript使用QWebChannel交互一——和Qt内嵌网页交互

    Qt和JavaScript使用QWebChannel交互一--和Qt内嵌网页交互 目录 Qt和JavaScript使用QWebChannel交互一--和Qt内嵌网页交互 前言 一.效果 二.实现过程 ...

  5. 关于Android避免按钮重复点击事件

    最近测试人员测试我们的APP的时候,喜欢快速点击某个按钮,出现一个页面出现多次,测试人员能不能禁止这样.我自己点击了几下,确实存在这个问题,也感觉用户体验不太好.于是乎后来我搜了下加一个方法放在我们U ...

  6. iOS之防止用户重复点击Button(按钮)问题

    在项目中,我们往往会遇到这样的问题:因为网络较慢的原因,用户会不耐烦的一直去点击按钮,这样导致的结果时:相关代码一遍一遍的被重复执行,如果按钮的事件是网络请求的话,这样又导致一种网络请求的循环.所以我 ...

  7. asp.net中如何防止用户重复点击提交按钮

    asp.net中如何防止用户重复点击提交按钮   asp.net 中防止因为网速慢等影响交互的问题导致用户可能点击多次提交按钮,从而导致数据库中出现多条重复的记录,经过亲自验证在网上找的方法,找到两个 ...

  8. 重复点击主界面(TabBar)按钮刷新界面--点击状态栏回到顶部

    1.监听按钮点击   2.判断是否是点击的同一个按钮(记录上次点击的按钮)   3.当重复点击相同按钮时,需要获取当前按钮对应控制器刷新界面      3.1 判断是否重复点击按钮,代码写在哪里?   ...

  9. 使用JavaScript动态的绑定、解绑 a 标签的onclick事件,防止重复点击

    页面上的 a 标签如下: <a class="more" style="cursor: pointer;" id="commentMore&qu ...

随机推荐

  1. 真机测试时的错误:No matching provisioning profiles found

    1.出现错误的原因是这样的---- 公司开始做项目,原来做真机测试的时候,用的是公司申请的苹果开发者账号.现在项目结束了,准备上线,但客户要求使用客户自己的苹果开发者是账号上线,于是就用客户的账号测试 ...

  2. 小波说雨燕 第三季 构建 swift UI 之 UI组件集-视图集(六)Picker View视图 学习笔记

    想对PickerView进行操作,只能在代码中操作. 下面 ,再添加三个label组件,然后将所有组件配置到代码中(看代码),然后要实现对PickerView的操作,就要实现它的DataSource协 ...

  3. Google自定义搜索引擎

    本文主要介绍如何通过Google的API来定义自己的搜索引擎,并将Google搜索框嵌入到自己的web页面.另外,分析了自定义搜索引擎请求数据的url,模拟请求并获取搜索的结果. 1 写在前面 前段时 ...

  4. 【转】JAVA CAS原理深度分析

    java.util.concurrent包完全建立在CAS之上的,没有CAS就不会有此包.可见CAS的重要性. CAS CAS:Compare and Swap, 翻译成比较并交换. java.uti ...

  5. FOJ 1683 纪念SlingShot(矩阵快速幂)

    C - 纪念SlingShot Description 已知 F(n)=3 * F(n-1)+2 * F(n-2)+7 * F(n-3),n>=3,其中F(0)=1,F(1)=3,F(2)=5, ...

  6. linux中C语言获取高精度时钟gettimeofday函数

    前言:    在开发中,很多时候需要知道各个函数或者是某些设备对命令的操作用时,因此需要用到 gettimeofday 来获取当前时钟. 一,函数说明 #include  int gettimeofd ...

  7. 巧用开发者工具的控制台来调试页面中的js语句

    因为要弄某网页的一个自动登陆工具,所以需要对此网页中的元素利用js进行选取和操作,复杂的js选取如果直接在头脑中想很容易出错,而且一旦出错也不好判断错误原因. 而浏览器带的开发者工具的控制台功能,就给 ...

  8. Can't initialize metastore for hive

    there maybe many reason to cause this,today our issue is that, if you execute hive –database dbname ...

  9. dipole antenna simulation by CST

    CST偶极子天线仿真,半波振子天线 一.本文使用CST仿真频率为1GHz的偶极子天线,使用2013版本.仿真的步骤为 1.选择一个CST的天线工程模板 2.设置好默认的单位 3.设置背景的材料(空气腔 ...

  10. 用c/c++混合编程方式为ios/android实现一个自绘日期选择控件(一)

    本文为原创,如有转载,请注明出处:http://www.cnblogs.com/jackybu 前言 章节: 1.需求描述以及c/c++实现日期和月历的基本操作 2.ios实现自绘日期选择控件 3.a ...