OAF 使用 javascript 使某个按钮在5秒内不能重复点击
首先要保证按钮是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秒内不能重复点击的更多相关文章
- 使用js使某个按钮在5秒内不能重复点击
<head> <!--参考:http://illy.iteye.com/blog/1534276 --> <!-- http://y.dobit.top/Detail/1 ...
- VS2010 使用时选择代码或双击时出错,点击窗口按钮后VS自动重启问题
VS2010 使用时选择代码或双击时出错崩溃,点击窗口按钮后VS自动重启问题 下载补丁,打上补丁之后,重启电脑,解决了问题. WindowsXP的下载地址:Windows XP 更新程序 (KB971 ...
- 关于javascript中限定时间内防止按钮重复点击的思路
前面的话 有一天心血来潮,1分钟内重复点击了多次博客园首页的刷新博文列表的刷新按钮.果不其然,ip当时就被禁用了.后来,重启自己的路由器,重新获取ip才可以访问博客园主页.那么,设置一个限定时间内(比 ...
- Qt和JavaScript使用QWebChannel交互一——和Qt内嵌网页交互
Qt和JavaScript使用QWebChannel交互一--和Qt内嵌网页交互 目录 Qt和JavaScript使用QWebChannel交互一--和Qt内嵌网页交互 前言 一.效果 二.实现过程 ...
- 关于Android避免按钮重复点击事件
最近测试人员测试我们的APP的时候,喜欢快速点击某个按钮,出现一个页面出现多次,测试人员能不能禁止这样.我自己点击了几下,确实存在这个问题,也感觉用户体验不太好.于是乎后来我搜了下加一个方法放在我们U ...
- iOS之防止用户重复点击Button(按钮)问题
在项目中,我们往往会遇到这样的问题:因为网络较慢的原因,用户会不耐烦的一直去点击按钮,这样导致的结果时:相关代码一遍一遍的被重复执行,如果按钮的事件是网络请求的话,这样又导致一种网络请求的循环.所以我 ...
- asp.net中如何防止用户重复点击提交按钮
asp.net中如何防止用户重复点击提交按钮 asp.net 中防止因为网速慢等影响交互的问题导致用户可能点击多次提交按钮,从而导致数据库中出现多条重复的记录,经过亲自验证在网上找的方法,找到两个 ...
- 重复点击主界面(TabBar)按钮刷新界面--点击状态栏回到顶部
1.监听按钮点击 2.判断是否是点击的同一个按钮(记录上次点击的按钮) 3.当重复点击相同按钮时,需要获取当前按钮对应控制器刷新界面 3.1 判断是否重复点击按钮,代码写在哪里? ...
- 使用JavaScript动态的绑定、解绑 a 标签的onclick事件,防止重复点击
页面上的 a 标签如下: <a class="more" style="cursor: pointer;" id="commentMore&qu ...
随机推荐
- IOS NSOperation&NSOperationQueue
NSOperation与NSOperationQueue的基本理论如下: 1.NSOperationQueue代表一个FIFO的队列,它负责管理系统提交的多个NSOperation,NSOp ...
- C语言-09-文件操作
文件类型 文本文件(ASCII) 简单的文本文件,可用任何文字处理程序阅读 二进制文件 包含 在ASCII及扩展ASCII字符中编写的数据或程序指令 的文件,通常图形文件及文字处理程序等计算机程序都属 ...
- iOS开发之网络编程--使用NSURLConnection实现大文件断点续传下载+使用输出流代替文件句柄
前言:本篇讲解,在前篇iOS开发之网络编程--使用NSURLConnection实现大文件断点续传下载的基础上,使用输出流代替文件句柄实现大文件断点续传. 在实际开发中,输入输出流用的比较少,但 ...
- Animated progress view with CAGradientLayer(带翻译)<待更新>
原文网址:使用CAGradientLayer的动画精度条View Modern software design is getting flatter and thinner all the time. ...
- java 的方法注释写在哪里?
如果有接口,写在接口方法上即可.鼠标滑过方法名时时会显示 如果没有接口,写在每个方法上方. eclipse 分三步 ① 找到方法,并将光标移动至方法名的上方 ②/** ③回车 那,效果是酱紫
- HTML页面定时跳转方法
1)html的实现 <head> <meta http-equiv="refresh" content="5;url=hello.html"& ...
- 优秀的PHP开源项目集合
包管理Package Management Package Management Related 框架 框架组件 微框架Micro Frameworks 内容管理系统Content Managemen ...
- JavaScript Patterns 4.6 Immediate Object Initialization
( { // here you can define setting values // a.k.a. configuration constants maxwidth : 600, maxheigh ...
- 将HTML特殊转义为实体字符的两种实现方式
前端开发工作中,经常需要将HTML的左右尖括号等转义成实体形式.我们不能把<,>,&等直接显示在最终看到的网页里.需要将其转义后才能在网页上显示. 转义字符(Escape Sequ ...
- PHP水印类
<?php /** * 水印类 * @author zhaoyingnan 2015/07/16 **/ include_once('extend.php'); class Watermark_ ...