2017-07-21 46 views
0

我有单选按钮和一个按钮,他们有自己的功能,我想将它们添加到另一个DIV不失其点击的活动和功能后,点击事件和功能,如何包括附加元素

我我正在工作,有一个woo-commerce的新闻发布网站,我不想触摸后面的单选按钮和按钮的wp-plugin的JS代码,因为它非常脆弱,我可能会破坏某些东西而使事情变得更糟。有没有解决这个问题的方法?

到目前为止我的代码

<div id="foo"> 
    <button> // i don't have an access to the click function of this 
    <radio button> // i don't have an access to the select function of this 
</div> 

<div id="bar"> 
</div> 

$('bar').append('foo'); 

其追加渣土,但你不能一下就可以了。

+0

您是否尝试使用有效的HTML? – adeneo

+0

此外,[无法重现](https://jsfiddle.net/adeneo/a9vhszqt/),追加现有的元素只是移动它,事件是完好无损的。 – adeneo

+0

什么是有效的html? html提供的wordpress我无法修改它.. –

回答

0

我做了什么,是我在JQuery中使用了clone和appendTo方法,首先我克隆了要移动到其他容器或div的元素,然后将显示设置为原来的全部,之后全部功能和事件正在起作用,

// the container 
$('.new_con_here').append('<div class="new_con"> </div>'); 

// the element that I want to move 
$('.elements').clone().appendTo('.new_con'); 

// set display none 
$('.old_con > .elements').css('display', 'none');