将内联点击函数编程移动到JQuery click()函数 [英] Programatically moving an inline onclick function to a JQuery click() function

查看:124
本文介绍了将内联点击函数编程移动到JQuery click()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够创建一个catch-all函数,这将允许我动态设置遗留系统上的属性。我想做的是创建一个JQuery点击功能,它将禁用元素,并提交表单或附加当前onclick函数到JQuery点击功能。 (假设onclick代码将处理表单)



到目前为止我有

  jQuery(element).click(function(){
onclick =(jQuery(this).attr('onclick')|| jQuery(this).attr('onClick'));
if(form&&!onclick){
jQuery(form).submit();
} else if(form&& onclick){
jQuery这个)//如何使用jquery动态执行onclick代码?
}};

p>

感谢您迄今为止的答案,但我需要进一步澄清问题。



我需要这是必要的,因为我必须取消设置onclick属性为了jQuery点击事件触发,但是我需要保留的jQuery点击事件,

解决方案

调用原生JavaScript onclick事件:

  this.click(); 


I'm hoping to be able to create a catch-all function which will allow me to dynamically set attributes on a legacy system. What I want to do is to create a JQuery click function which will disable the element and either submit the form or append the current onclick function to the JQuery click function. (It is assumed that the onclick code will handle the form)

So far I have

jQuery(element).click( function() {
onclick = (jQuery(this).attr('onclick') || jQuery(this).attr('onClick'));
if(form && !onclick) {
    jQuery(form).submit();
} else if (form && onclick) {
    jQuery(this).//how do I dynamically execute the onclick code using jquery?
}};

To the best of my knowledge this should be possible in javascript, however I can't find any similar threads.

EDIT

Thank you for the answers so far, however I need to clarify the problem further.

I need to be able to take the function currently in |tag "onclick=function()| and append that to the jQuery click function. This is necessary since I must unset the onclick attribute in order for the jQuery click event to fire, however I need to preserve the original functionality.

解决方案

Call the native javascript onclick event like that:

this.click();

这篇关于将内联点击函数编程移动到JQuery click()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆