[英]Drag and Drop functionality is not working
I am creating one page in which I have one fav_div
in which I want to drop some button from sourcePopup
which is popover but unable to drop. 我创建一个页面中,我有一个fav_div
中,我想删除一些按钮sourcePopup
这是酥料饼,但无法删除。
Here is Exception which I ma getting. 这是我要得到的例外。
Uncaught TypeError: Cannot read property 'cloneNode' of null
Here is my code. 这是我的代码。
<script>
function drag(e) {
e.dataTransfer.setData("Text", e.target.id);
}
function allowDrop(e) {
e.preventDefault();
}
function drop(e) {
e.preventDefault();
var el = document.getElementById(e.dataTransfer.getData('Text'));
var y = el.cloneNode(true);
var links = document.getElementById("fav_div").querySelectorAll('button');
var isAvailable = false;
for (var i = 0; i < links.length; i++) {
console.log("fav_id:- "+links[i].id + " y.id :- " +y.id);
if(links[i].id == y.id){
alert(y.id+' already present');
isAvailable = true;
}else{
isAvailable = false;
}
}
if(!isAvailable){
e.target.appendChild(y);
document.getElementById(y.id).className = "";
document.getElementById(y.id).className = "btn-primary-custom";
}
}
</script>
<div id="sourcePopover" class="container hide">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 remove-grid-padding margin-2px" >
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 padding-2px" >
<button class="btn btn-secondary btn-popup-sources" id="source_btn_one" draggable="true" ondragstart="drag(event)" onclick="buttonPressed(this.id)">
<img src="images/one.png" class="img-responsive popup-source-image" style="padding:5px" > <br/>
<span class="popup-source-text"> one </span>
</button>
</div>
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 padding-2px" >
<button class="btn btn-secondary btn-popup-sources center-block" id="source_btn_two" draggable="true" ondragstart="drag(event)" onclick="buttonPressed(this.id)">
<img src="images/two.png" class="img-responsive popup-source-image" > <br/>
<span class="popup-source-text"> two </span>
</button>
</div>
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 padding-2px" >
<button class="btn btn-secondary btn-popup-sources center-block" id="source_btn_three" draggable="true" ondragstart="drag(event)" onclick="buttonPressed(this.id)">
<img src="images/three.png" style="padding:5px" class="img-responsive popup-source-image" > <br/>
<span class="popup-source-text"> three </span>
</button>
</div>
</div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 remove-grid-padding margin-2px" >
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 padding-2px" >
<button class="btn btn-secondary btn-popup-sources center-block" id="source_btn_four" draggable="true" ondragstart="drag(event)" onclick="buttonPressed(this.id)">
<img src="images/four.png" class="img-responsive popup-source-image" > <br/>
<span class="popup-source-text"> four </span>
</button>
</div>
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 padding-2px" >
<button class="btn btn-secondary btn-popup-sources center-block" id="source_btn_five" draggable="true" ondragstart="drag(event)" onclick="buttonPressed(this.id)">
<img src="images/five.png" class="img-responsive popup-source-image"> <br/>
<span class="popup-source-text"> five </span>
</button>
</div>
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 padding-2px" >
<button class="btn btn-secondary btn-popup-sources center-block" id="source_btn_six" draggable="true" ondragstart="drag(event)" onclick="buttonPressed(this.id)">
<img src="images/six.png" class="img-responsive popup-source-image" > <br/>
<span class="popup-source-text"> six </span>
</button>
</div>
</div>
<div class="btn-group-vertical center-block" id="fav_div" ondragover="allowDrop(event)" ondrop="drop(event)">
<a data-toggle="popover" data-trigger="focus" >
<button type="button" class="btn btn-secondary btn-primary-custom btn-primary-custom-text"
id="btn_select_source" >Select
</button>
</a>
<a data-toggle="tab" href="#eleven" >
<button type="button" class="btn btn-secondary btn-primary-custom" id="btn_eleven" onclick="buttonPressed(this.id)">
<img src="images/eleven.png" class="img-responsive" >
</button>
</a>
<a data-toggle="tab" href="#thirteen" >
<button type="button" class="btn btn-secondary btn-primary-custom " id="btn_thirteen" onclick="buttonPressed(this.id)">
thirteen
</button>
</a>
<a data-toggle="nine" href="#nine">
<button type="button" class="btn btn-secondary btn-primary-custom" id="btn_nine" onclick="buttonPressed(this.id)">
nine
</button>
</a>
<a data-toggle="tab" href="#ten" >
<button type="button" class="btn btn-secondary btn-primary-custom" id="btn_ten" onclick="buttonPressed(this.id)">
<img src="images/ten.png" class="img-responsive center-block" > <div class="circle"></div>
</button>
</a>
The first problem that pops up for me is, that you closed the <head>
to early. 对我而言,出现的第一个问题是您将<head>
提前关闭了。
The second error is, that you closed the </article>
but hadn't opened an <article>
field. 第二个错误是,您关闭了</article>
但没有打开<article>
字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.