简体   繁体   English

将一个HTML属性onClick函数与一个jQuery On函数结合起来?

[英]Combine an HTML attribute onClick function with a jQuery On function?

There's a site I'm working on with legacy onclick functions on input elements: 我正在使用输入元素上的遗留onclick函数的网站:

<input name="input_41" type="radio" value="76" id="choice_41_1" onclick="gf_apply_rules(5,[6,7,8]);">

Unfortunately, I can't change or modify the legacy code directly. 不幸的是,我无法直接更改或修改遗留代码。

I'm also trying to update the site and make the form elements prettier with additional CSS and JS. 我也试图更新网站,并使用额外的CSS和JS使表单元素更漂亮。 One of the new functions I'm using to handle radio elements uses the jQuery On() function. 我用来处理无线电元素的新函数之一使用jQuery On()函数。 This function works well but appears to override the existing onclick function gf_apply_rules() . 此函数运行良好,但似乎覆盖现有的onclick函数gf_apply_rules() Here is an example of the jQuery: 这是jQuery的一个例子:

$(document).on('click.radio.data-api', '[data-toggle^=radio], .radio', function (e) {
    var $radio = $(e.target);
    e && e.preventDefault() && e.stopPropagation();
    if (!$radio.hasClass('radio')) $radio = $radio.closest('.radio');
    $radio.find(':radio').radio('toggle');
});

Is there anyway I can keep the existing HTML specified onclick function firing with On() ? 无论如何我可以保持现有的HTML指定onclick函数触发On()

The e.preventDefault() will prevent the original (older) onclick handler. e.preventDefault()将阻止原始(较旧的)onclick处理程序。 Did you try removing that line to see if both event handlers get called. 您是否尝试删除该行以查看是否同时调用了两个事件处理程序。 . . ?

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

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