简体   繁体   English

我们可以在Java脚本验证功能中包含jquery吗?

[英]can we include jquery inside a java script validation function?

I have a JavaScript validation function and a jquery progress bar. 我有一个JavaScript验证功能和一个jquery进度栏。 onclick of a button it is doing some validation and then some long database query in the background.I want to have a progress bar when this query is going on as well as that JavaScript function to execute before the back-ground process starts. 一个按钮的onclick会进行一些验证,然后在后台进行一些长时间的数据库查询。我想在进行此查询时有一个进度条,以及要在后台进程开始之前执行的JavaScript函数。 here is where it is calling JavaScript function 这是调用JavaScript函数的地方

<input name="btnPublish" class="button1" type="button" id="btnPublish" value="Publish" onClick="disableActiveButtons()"> 

my jquery is like:: 我的jQuery就像:

$('#btnPublish').click(function() { 
                     var val = 0;
                     var interval = setInterval(function(){ 
                     val = val+1;    
                     $('#pb').progressbar({ value: val});   
                     $('#percent').text(val + '%'); 
                     if(val == 100){
                         clearInterval(interval);
                        }
                     }, 50);
                     });

can i include this jquery inside the JavaScript validation function so that both of them works? 我可以在JavaScript验证功能中包含此jquery,以便它们都可以工作吗? if not how should i implement so that I have progress bar and JavaScript validation too? 如果不是,我应该如何实现,以便我也有进度条和JavaScript验证? Thanks 谢谢

To call the javascript function from within your JQuery onClick you would do : 要从JQuery onClick内调用javascript函数,您需要执行以下操作:

Remove onclick attribute fom the input tag : 从输入标签中删除onclick属性:

<input name="btnPublish" class="button1" type="button" id="btnPublish" value="Publish"> 

And call the function as : 并将函数调用为:

$('#btnPublish').click(function() { 

                 if(!disableActiveButtons()) 
                     return false; //cancel the event if validation failed , else continue 
                 var val = 0;
                 var interval = setInterval(function(){ 
                 val = val+1;    
                 $('#pb').progressbar({ value: val});   
                 $('#percent').text(val + '%'); 
                 if(val == 100){
                     clearInterval(interval);
                    }
                 }, 50);
                 });

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM