我正在将克隆方法应用于克隆元素并将其附加到我的要求中。一切正常,但我无法点击克隆的元素。我试图找到解决方案,但我没有得到它,请指导我解决问题 查看我附上的代码
$('.circle').click(function() {
if ($(this).closest("li").children("ol").length) {
debugger;
var clonediv = $(this).closest('li');
var clndiv = $(this).parentsUntil('li').siblings('ol').children('li:eq(0)');
var newdiv = clonediv.clone(true, true);
newdiv.html('<div>' + clonediv.find('div').eq(0).html() + '</div>');
newdiv.find('.circle').removeClass('circle').addClass('close');
newdiv.insertAfter(clndiv);
} else {
var clonediv = $(this).parentsUntil('li');
var clndiv = $(this).closest('ol');
var newdiv = clndiv.clone(true, true);
newdiv.html('<li><div>' + clonediv.html() + '</div></li>');
newdiv.find('.circle').removeClass('circle').addClass('close');
newdiv.insertAfter(clonediv);
}
});
$('.close').on('click', function() {
$(this).closest('li').remove();
console.log('remove');
});
$('li div :header').each(function(index) {
$("li div :header").get(index).contentEditable = "true";
});*,
*:before,
*:after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
background-color: #f6f9fb;
font-family: 'Helvetica Neue', 'Helvetica', Arial, sans-serif;
}
h1 {
color: #fff;
text-align: center;
}
#wrapper {
margin: 150px auto;
max-width: 80em;
}
#container {
float: left;
padding: 1em;
width: 100%;
}
.low_pr {
margin-top: 15px;
position: relative;
}
.low_pr:before {
height: 1em!important;
left: 50%!important;
top: -15px!important;
width: 3px!important;
background-color: #b7a6aa;
content: '';
position: absolute;
}
.ver_low_pr {
margin-left: 15px;
position: relative;
}
.ver_low_pr:before {
height: 3px;
left: -15px;
top: 1em;
width: 1em;
background-color: #b7a6aa;
content: '';
position: absolute;
}
ol.organizational-chart,
ol.organizational-chart ol,
ol.organizational-chart li,
ol.organizational-chart li>div {
position: relative;
}
ol.organizational-chart,
ol.organizational-chart ol {
list-style: none;
margin: 0;
padding: 0;
}
ol.organizational-chart {
text-align: center;
}
ol.organizational-chart ol {
padding-top: 1em;
}
ol.organizational-chart ol:before,
ol.organizational-chart ol:after,
ol.organizational-chart li:before,
ol.organizational-chart li:after,
ol.organizational-chart>li>div:before,
ol.organizational-chart>li>div:after {
background-color: #b7a6aa;
content: '';
position: absolute;
}
ol.organizational-chart ol>li {
padding: 1em 0 0 1em;
}
ol.organizational-chart>li ol:before {
height: 1em;
left: 50%;
top: 0;
width: 3px;
}
ol.organizational-chart>li ol:after {
height: 3px;
left: 3px;
top: 1em;
width: 50%;
}
ol.organizational-chart>li ol>li:not(:last-of-type):before {
height: 3px;
left: 0;
top: 2em;
width: 1em;
}
ol.organizational-chart>li ol>li:not(:last-of-type):after {
height: 100%;
left: 0;
top: 0;
width: 3px;
}
ol.organizational-chart>li ol>li:last-of-type:before {
height: 3px;
left: 0;
top: 2em;
width: 1em;
}
ol.organizational-chart>li ol>li:last-of-type:after {
height: 2em;
left: 0;
top: 0;
width: 3px;
}
ol.organizational-chart li>div {
background-color: #fff;
border-radius: 3px;
min-height: 2em;
padding: 1.5em 0.5em;
position: relative;
border: 1px solid #292626;
}
ol.organizational-chart li>div * {
outline: 0;
}
ol.organizational-chart li>div .circle {
position: absolute;
right: -5px;
top: -5px;
width: 16px;
height: 16px;
border-radius: 100%;
cursor: pointer;
color: #ffffff;
background: #292626;
font-size: 14px;
line-height: 16px;
text-align: center;
}
ol.organizational-chart li>div .close {
position: absolute;
right: -5px;
top: -5px;
width: 16px;
height: 16px;
border-radius: 100%;
cursor: pointer;
color: #ffffff;
background: #292626;
font-size: 14px;
line-height: 16px;
text-align: center;
transform: rotate(45deg);
-moz-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
}
/*** PRIMARY ***/
ol.organizational-chart>li>div {
background-color: #a2a2a2;
margin-right: 1em;
}
ol.organizational-chart>li>div:before {
bottom: 2em;
height: 3px;
right: -1em;
width: 1em;
}
ol.organizational-chart>li>div:first-of-type:after {
bottom: 0;
height: 2em;
right: -1em;
width: 3px;
}
ol.organizational-chart>li>div+div {
margin-top: 1em;
}
ol.organizational-chart>li>div+div:after {
height: calc(100% + 1em);
right: -1em;
top: -1em;
width: 3px;
}
/*** SECONDARY ***/
ol.organizational-chart>li>ol:before {
left: inherit;
right: 0;
}
ol.organizational-chart>li>ol:after {
left: 0;
width: 100%;
}
ol.organizational-chart>li>ol>li>div {
background-color: #eaf5f4;
}
/*** TERTIARY ***/
ol.organizational-chart>li>ol>li>ol>li>div {
background-color: #f5e7e8;
}
/*** QUATERNARY ***/
ol.organizational-chart>li>ol>li>ol>li>ol>li>div {
background-color: #fff5ec;
}
/*** QUINARY ***/
ol.organizational-chart>li>ol>li>ol>li>ol>li>ol>li>div {
background-color: #e6e5de;
}
/*** MEDIA QUERIES ***/
@media only screen and ( min-width: 64em) {
ol.organizational-chart {
margin-left: -1em;
margin-right: -1em;
}
/* PRIMARY */
ol.organizational-chart>li>div {
display: inline-block;
float: none;
margin: 0 1em 1em 1em;
vertical-align: bottom;
}
ol.organizational-chart>li>div:only-of-type {
margin-bottom: 0;
width: calc((50% / 1) - 2em - 4px);
}
ol.organizational-chart>li>div:first-of-type:nth-last-of-type(2),
ol.organizational-chart>li>div:first-of-type:nth-last-of-type(2)~div {
width: calc((100% / 2) - 2em - 4px);
}
ol.organizational-chart>li>div:first-of-type:nth-last-of-type(3),
ol.organizational-chart>li>div:first-of-type:nth-last-of-type(3)~div {
width: calc((100% / 3) - 2em - 4px);
}
ol.organizational-chart>li>div:first-of-type:nth-last-of-type(4),
ol.organizational-chart>li>div:first-of-type:nth-last-of-type(4)~div {
width: calc((100% / 4) - 2em - 4px);
}
ol.organizational-chart>li>div:first-of-type:nth-last-of-type(5),
ol.organizational-chart>li>div:first-of-type:nth-last-of-type(5)~div {
width: calc((100% / 5) - 2em - 4px);
}
ol.organizational-chart>li>div:before,
ol.organizational-chart>li>div:after {
bottom: -1em!important;
top: inherit!important;
}
ol.organizational-chart>li>div:before {
height: 1em!important;
left: 50%!important;
width: 3px!important;
}
ol.organizational-chart>li>div:only-of-type:after {
display: none;
}
ol.organizational-chart>li>div:first-of-type:not(:only-of-type):after,
ol.organizational-chart>li>div:last-of-type:not(:only-of-type):after {
bottom: -1em;
height: 3px;
width: calc(50% + 1em + 3px);
}
ol.organizational-chart>li>div:first-of-type:not(:only-of-type):after {
left: calc(50% + 3px);
}
ol.organizational-chart>li>div:last-of-type:not(:only-of-type):after {
left: calc(-1em - 3px);
}
ol.organizational-chart>li>div+div:not(:last-of-type):after {
height: 3px;
left: -2em;
width: calc(100% + 4em);
}
/* SECONDARY */
ol.organizational-chart>li>ol {
display: flex;
display: -webkit-flex;
display: -moz-flex;
display: -ms-flexbox;
flex-wrap: nowrap;
}
ol.organizational-chart>li>ol:before,
ol.organizational-chart>li>ol>li:before {
height: 1em!important;
left: 50%!important;
top: 0!important;
width: 3px!important;
}
ol.organizational-chart>li>ol:after {
display: none;
}
ol.organizational-chart>li>ol>li {
flex-grow: 1;
-ms-flex-grow: 1;
-webkit-flex-grow: 1;
padding-left: 1em;
padding-right: 1em;
padding-top: 1em;
}
ol.organizational-chart>li>ol>li:only-of-type {
padding-top: 0;
}
ol.organizational-chart>li>ol>li:only-of-type:before,
ol.organizational-chart>li>ol>li:only-of-type:after {
display: none;
}
ol.organizational-chart>li>ol>li:first-of-type:not(:only-of-type):after,
ol.organizational-chart>li>ol>li:last-of-type:not(:only-of-type):after {
height: 3px;
top: 0;
width: 50%;
}
ol.organizational-chart>li>ol>li:first-of-type:not(:only-of-type):after {
left: 50%;
}
ol.organizational-chart>li>ol>li:last-of-type:not(:only-of-type):after {
left: 0;
}
ol.organizational-chart>li>ol>li+li:not(:last-of-type):after {
height: 3px;
left: 0;
top: 0;
width: 100%;
}
}<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="wrapper">
<div id="container">
<ol class="organizational-chart">
<li>
<div>
<h1>
A</h1>
<div class="circle">
+</div>
</div>
<ol>
<li>
<div>
<h2>
AA</h2>
<div class="circle">
+</div>
</div>
<ol>
<li>
<div>
<h3>
AAA</h3>
<div class="circle">
+</div>
</div>
</li>
<li>
<div>
<h3>
AAB</h3>
<div class="circle">
+</div>
</div>
<ol>
<li>
<div>
<h4>
AAAA</h4>
<div class="circle">
+</div>
</div>
</li>
<li>
<div>
<h4>
AAAB</h4>
<div class="circle">
+</div>
</div>
<ol>
<li>
<div>
<h5>
AAAAA</h5>
<div class="circle">
+</div>
</div>
</li>
<li>
<div>
<h5>
AAAAB</h5>
<div class="circle">
+</div>
</div>
<ol>
<li>
<div>
<h6>
AAAAAA</h6>
<div class="circle">
+</div>
</div>
</li>
</ol>
</li>
</ol>
</li>
<li>
<div>
<h4>
AAAC</h4>
<div class="circle">
+</div>
</div>
</li>
</ol>
</li>
<li>
<div>
<h3>
AAC</h3>
<div class="circle">
+</div>
</div>
</li>
</ol>
</li>
<li>
<div>
<h2>
BB</h2>
<div class="circle">
+</div>
</div>
<ol>
<li>
<div>
<h3>
Tertiary</h3>
<div class="circle">
+</div>
</div>
<ol>
<li>
<div>
<h4>
Quaternary</h4>
<div class="circle">
+</div>
</div>
<ol>
<li>
<div class="ver_low_pr">
<h5>
Quinary</h5>
<div class="circle">
+</div>
</div>
<ol>
<li>
<div>
<h6>
Senary</h6>
<div class="circle">
+</div>
</div>
</li>
<li>
<div class="ver_low_pr">
<h6>
Senary</h6>
<div class="circle">
+</div>
</div>
</li>
</ol>
</li>
<li>
<div>
<h5>
Quinary</h5>
<div class="circle">
+</div>
</div>
</li>
</ol>
</li>
</ol>
</li>
<li>
<div>
<h3>
Tertiary</h3>
<div class="circle">
+</div>
</div>
</li>
<li>
<div>
<h3>
Tertiary</h3>
<div class="circle">
+</div>
</div>
</li>
</ol>
</li>
</ol>
</li>
</ol>
</div>
</div>
最佳答案
您需要使用 event-delegation
$(document).on('click','.circle',function () {
和
$(document).on('click','.close',function() {
关于jquery - 带有 clone(true) 单击的克隆元素不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49023522/
如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象
rails中是否有任何规定允许站点的所有AJAXPOST请求在没有authenticity_token的情况下通过?我有一个调用Controller方法的JqueryPOSTajax调用,但我没有在其中放置任何真实性代码,但调用成功。我的ApplicationController确实有'request_forgery_protection'并且我已经改变了config.action_controller.consider_all_requests_local在我的environments/development.rb中为false我还搜索了我的代码以确保我没有重载ajaxSend来发送
查看我的Ruby代码:h=Hash.new([])h[0]=:word1h[1]=h[1]输出是:Hash={0=>:word1,1=>[:word2,:word3],2=>[:word2,:word3]}我希望有Hash={0=>:word1,1=>[:word2],2=>[:word3]}为什么要附加第二个哈希元素(数组)?如何将新数组元素附加到第三个哈希元素? 最佳答案 如果您提供单个值作为Hash.new的参数(例如Hash.new([]),完全相同的对象将用作每个缺失键的默认值。这就是您所拥有的,那是你不想要的。您可以改用
本文主要介绍在使用Selenium进行自动化测试或者任务时,对于使用了iframe的页面,如何定位iframe中的元素文章目录场景描述解决方案具体代码场景描述当我们在使用Selenium进行自动化测试的时候,可能会遇到一些界面或者窗体是使用HTML的iframe标签进行承载的。对于iframe中的标签,如果直接查找是无法找到的,会抛出没有找到元素的异常。比如近在咫尺的例子就是,CSDN的登录窗体就是使用的iframe,大家可以尝试通过F12开发者模式查看到的tag_name,class_name,id或者xpath来定位中的页面元素,会抛出NoSuchElementException异常。解决
使用rspec-rails3.0+,测试设置分为spec_helper和rails_helper我注意到生成的spec_helper不需要'rspec/rails'。这会导致zeus崩溃:spec_helper.rb:5:in`':undefinedmethod`configure'forRSpec:Module(NoMethodError)对thisissue最常见的回应是需要'rspec/rails'。但这是否会破坏仅使用spec_helper拆分rails规范和PORO规范的全部目的?或者这无关紧要,因为Zeus无论如何都会预加载Rails?我应该在我的spec_helper中做
我是HanamiWorld的新人。我已经写了这段代码:moduleWeb::Views::HomeclassIndexincludeWeb::ViewincludeHanami::Helpers::HtmlHelperdeftitlehtml.headerdoh1'Testsearchengine',id:'title'hrdiv(id:'test')dolink_to('Home',"/",class:'mnu_orizontal')link_to('About',"/",class:'mnu_orizontal')endendendendend我在模板上调用了title方法。htm
给定一个nxmbool数组:[[true,true,false],[false,true,true],[false,true,true]]有什么简单的方法可以返回“该列中有多少个true?”结果应该是[1,3,2] 最佳答案 使用转置得到一个数组,其中每个子数组代表一列,然后将每一列映射到其中的true数:arr.transpose.map{|subarr|subarr.count(true)}这是一个带有inject的版本,应该在1.8.6上运行,没有任何依赖:arr.transpose.map{|subarr|subarr.in
假设我有一个类A,里面有一些方法。假设stringmethodName是这些方法之一,我已经知道我想给它什么参数。它们在散列中{'param1'=>value1,'param2'=>value2}所以我有:params={'param1'=>value1,'param2'=>value2}a=A.new()a.send(methodName,value1,value2)#callmethodnamewithbothparams我希望能够通过传递我的哈希以某种方式调用该方法。这可能吗? 最佳答案 确保methodName是一个符号,而
我有一个电子邮件表格。但是我正在制作一个测试电子邮件表单,用户可以在其中添加一个唯一的电子邮件,并让电子邮件测试将其发送到该特定电子邮件。为了简单起见,我决定让测试电子邮件通过ajax执行,并将整个内容粘贴到另一个电子邮件表单中。我不知道如何将变量从我的HAML发送到我的Controllernew.html.haml-form_tagadmin_email_blast_pathdoSubject%br=text_field_tag'subject',:class=>"mass_email_subject"%brBody%br=text_area_tag'message','',:nam
在Ruby中,是否有一种简单的方法可以将n维数组中的每个元素乘以一个数字?这样:[1,2,3,4,5].multiplied_by2==[2,4,6,8,10]和[[1,2,3],[1,2,3]].multiplied_by2==[[2,4,6],[2,4,6]]?(很明显,我编写了multiplied_by函数以区别于*,它似乎连接了数组的多个副本,不幸的是这不是我需要的)。谢谢! 最佳答案 它的长格式等价物是:[1,2,3,4,5].collect{|n|n*2}其实并没有那么复杂。你总是可以使你的multiply_by方法:c