여기에 명백한 내용이 표시되지 않습니까? 나는 비슷한 문제에 대한 수십 가지 해결책을 보았지만 나와 함께 간신히 그들은 일하지 않았다.jQuery에서 자식으로 전달이 중지됩니다.
$(document).ready(function() {
$(".init-tutorial").on("click", function(e){
var template = $(".pointer.template");
var posX = e.pageX - $(this).position().left - 8,
posY = e.pageY - $(this).position().top - 8;
template
.clone()
.removeClass("template")
.css({"top":posY,"left":posX}).attr("tabindex",-1)
.appendTo($(this)).focus();
});
$(document).on("click", ".comments", function(e){
e.stopPropagation();
});
});
.template (.comments 포함)는 모든 클릭을 상위 엘로 전파하므로 바람직하지 않습니다.
내가 막을 수 있었던 방법은 if (e.target === this)
를 사용하고 있었다. 그러나 이것은 이벤트를 수신해야하는 여러 요소를 가지고 있기 때문에 나에게 또 다른 문제를 일으킨다.
템플릿 마크 업 : 컨테이너 사업부에 대한
<div class="pointer template" style="">
<div class="comments">
<div class="panel panel-default">
<div class="panel-body">
<textarea class="form-control" rows="3" placeholder="კომენტარი"></textarea>
<button type="button" class="btn btn-success btn-block">დაპოსტე</button>
</div>
</div>
</div>
</div>
, 그것은 특별한 아무것도 없다
<div class="init-tutorial" style="height:400px;width:400px;background-color:red;"></div>
jsfidle : http://jsfiddle.net/9cjrp079/
당신이 마크 업을 제공 할 수 있습니까? 표식이 없으면 코드가 어떻게 작동해야하는지 또는 작동하지 않아야 하는지를 결정할 수 없습니다. – Terry
@Terry 마크 업이 제공되면, 지금 빠른 jsfiddle를 만들 것입니다. –
@Terry http://jsfiddle.net/9cjrp079/ –