Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript/jQuery查找&;代替_Javascript_Jquery_Replace_Find - Fatal编程技术网

Javascript/jQuery查找&;代替

Javascript/jQuery查找&;代替,javascript,jquery,replace,find,Javascript,Jquery,Replace,Find,我想找到: 并将其替换为: 简而言之,插入applyCode()到点击我不认为查找和替换是最好的选择。相反,您可以使用Javascript为您附加事件。使用jQuery标记问题后,请尝试以下操作: <input type="button" class=" btn btn-lg btn-info" value="Continue"> 请注意,上面的选择器纯粹是为了演示,您最好在元素上设置一个id属性,或者设置一个特定的class,然后通过该属性来选择它。您甚至可以挂接到表单的s

我想找到:

并将其替换为:


简而言之,插入
applyCode()
点击

我不认为查找和替换是最好的选择。相反,您可以使用Javascript为您附加事件。使用jQuery标记问题后,请尝试以下操作:

<input type="button" class=" btn btn-lg btn-info" value="Continue"> 

请注意,上面的选择器纯粹是为了演示,您最好在元素上设置一个
id
属性,或者设置一个特定的
class
,然后通过该属性来选择它。您甚至可以挂接到表单的
submit
事件,假设此按钮用于此目的。

您可以做两件事。方法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()的相同元素,可以使用
$。\u 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.
        });
    });

实施:

此解决方案有效!谢谢但是,正如你提到的,它需要一个ID。我不能添加ID,因为代码已经给出,不能修改。有没有办法按属性获取元素?loadFina()的值;在整个文档中是唯一的。确定。理解。我从代码中删除了:load final();,这反过来适用于:applyCode();对所有人来说,这没关系。谢谢对吗?这些解决方案有效!谢谢但正如下面的文章所提到的,我需要一个ID或某种方式只针对该输入,因为这不是文档上唯一的输入标记。是否可以使用load final()将其作为目标;因为它在文档中是唯一的。我已经更新了解决方案。请按照标有更新的部分进行操作。我看到您是通过ID“btn1”获取元素的。但是,我无法将该ID添加到表单中。我没有访问源代码的权限。这可以通过onclick值使用get元素来完成吗?不幸的是,这是唯一一个使用jQuery1.10+的本机解决方案。如果这不适合你,你可能想看看其他API,比如OK。理解。我使用了第一个解决方案的方法2。这反过来适用于:applyCode();对所有人来说,这没关系。谢谢对吗?
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.
        });
    });