Javascript HTML5计数器上的下拉函数
我在试着做一些谜题。 我已经完成了本教程: 将text div改为picture,一切都很正常,直到我想在移动中添加计数器为止。对于文本,一切都很好,但若我有图像,countnumber会覆盖我的图像 我试过了Javascript HTML5计数器上的下拉函数,javascript,html,image,Javascript,Html,Image,我在试着做一些谜题。 我已经完成了本教程: 将text div改为picture,一切都很正常,直到我想在移动中添加计数器为止。对于文本,一切都很好,但若我有图像,countnumber会覆盖我的图像 我试过了 document.getElementById("some-new-div").innerHTML+= 'moves: ' + newCount; 但它不起作用 this.handleDrop = function(e) { // this/e.target is curr
document.getElementById("some-new-div").innerHTML+= 'moves: ' + newCount;
但它不起作用
this.handleDrop = function(e) {
// this/e.target is current target element.
if (e.stopPropagation) {
e.stopPropagation(); // stops the browser from redirecting.
}
// Don't do anything if we're dropping on the same column we're dragging.
if (dragSrcEl_ != this) {
dragSrcEl_.innerHTML = this.innerHTML;
this.innerHTML = e.dataTransfer.getData('text/html');
// Set number of times the column has been moved. <-----------------------------------------------
var count = this.querySelector('.count');
var newCount = parseInt(count.getAttribute('data-col-moves')) + 1;
count.setAttribute('data-col-moves', newCount);
count.textContent = 'moves: ' + newCount;
//document.getElementById("count1").innerHTML+= 'moves: ' + newCount;
}
return false;
};
this.handleDrop=函数(e){
//此/e.target是当前目标元素。
如果(如停止播放){
e、 stopPropagation();//停止浏览器重定向。
}
//如果我们正在拖放同一列,请不要执行任何操作。
如果(dragSrcEl_!=此){
dragSrcEl_u2;.innerHTML=this.innerHTML;
this.innerHTML=e.dataTransfer.getData('text/html');
//设置列移动的次数。John
我认为问题在于,当您更新count元素的textContent时,它会覆盖中的标记代码。请尝试将图像分配给的background image CSS属性。例如,将示例HTML代码中的替换为:
<table>
<tr><td><div class="column"><div class="count" data-col-moves="0" style="background-image:url('img/img1.jpg');width:50px;height:50px;" alt='img1.jpg'></div></div></td>
<td><div class="column" style="background-image:url('img/img2.jpg');width:50px;height:50px;" alt='img2.jpg'></div></td>
<td><div class="column" style="background-image:url('img/img3.jpg');width:50px;height:50px;" alt='img3.jpg'></div></td>
<td><div class="column" style="background-image:url('img/img4.jpg');width:50px;height:50px;" alt='img4.jpg'></div></td></tr>
如果图像大于50x50像素,只需使用“column”类重置上的宽度和高度CSS属性
<table>
<tr><td><div class="column"><div class="count" data-col-moves="0" style="background-image:url('img/img1.jpg');width:50px;height:50px;" alt='img1.jpg'></div></div></td>
<td><div class="column" style="background-image:url('img/img2.jpg');width:50px;height:50px;" alt='img2.jpg'></div></td>
<td><div class="column" style="background-image:url('img/img3.jpg');width:50px;height:50px;" alt='img3.jpg'></div></td>
<td><div class="column" style="background-image:url('img/img4.jpg');width:50px;height:50px;" alt='img4.jpg'></div></td></tr>