gpt4 book ai didi

Javascript/jQuery 查找和替换

转载 作者:行者123 更新时间:2023-12-02 15:21:27 25 4
gpt4 key购买 nike

我想找到:

<input type="button" class=" btn btn-lg btn-info" value="Continue" onclick="loadFinal();">

并将其替换为:

<input type="button" class=" btn btn-lg btn-info" value="Continue" onclick="loadFinal(); applyCode();">

简而言之,插入 applyCode();onclick .

最佳答案

您可以做两件事。方法 1 将从按钮中删除所有点击事件并添加事件,方法 2 将在现有事件之外添加其他事件。

方法 1

$('input:button').unbind('click'); // remove all click events associated
$('input:button').on("click",function() // add new click events
{
loadFinal();
applyCode();
});

方法 2

$('input:button').on("click",function() // add additional click events
{
applyCode();
});

更新:

为了将 applycode() 事件应用或附加到具有 loadfinal() 的同一元素,您可以使用 $._data 提取事件并检查某个事件是否存在。

$("input:button").click(function() {
var events = $._data(document.getElementById('btn1'), "events");
$.each(events,function(i,o)
{
alert(i);// give the event type like 'click'
alert(o); // give the event object - you can extract the event name from the object and do the compare with the existint event.
});
});

或者,您可以直接定位点击事件。

var events = $._data(document.getElementById('btn1'), "events").click;
$.each(events,function(i,o)
{
alert(i);// give the index
alert(o); // give the event object - you can extract the event name from the object and do the compare with the existint event.
});
});

实现:http://jsfiddle.net/qk5qj33u/15/

关于Javascript/jQuery 查找和替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34008848/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com