2017-11-11 26 views

답변

0

javascript를 사용하여 특정 구성 요소의 텍스트 끌기를 비활성화 할 수 있습니다.

<textbox value="Drag Me!" /> 
<textbox value="Can't drag me!" sclass="nodrag" /> 
<textbox placeholder="Can drop here..." /> 
<textbox placeholder="...but not here" sclass="nodrop" /> 

<script type="text/javascript"> 
    document.body.addEventListener("dragstart", function(e) { 
     if (e.target.className.indexOf("nodrag") > -1) { 
      e.preventDefault(); 
      return false; 
     }       
    }, false); 
    document.body.addEventListener("dragover", function(e) { 
     if (e.target.className.indexOf("nodrop") > -1) { 
      e.preventDefault(); 
      e.dataTransfer.effectAllowed = "none"; 
      e.dataTransfer.dropEffect = "none"; 
      return false; 
     }       
    }, false); 
</script> 

당신은 또한 작업을 수행 할 수 있습니다 구성 요소에 이러한 코드를 적용하는 방법은 여러 가지가 있으며, 그 다음은 단지 텍스트 상자의 소수를 위해 필요하면 매우 편리 마커, 같은 sclass를 사용 zk.afterLoad를 통해 :

zk.afterLoad('zul.inp', function() { 
    var xTextbox = {}; 
    zk.override(zul.inp.Textbox.prototype, xTextbox , { 
     bind_ : function() { 
      this.$supers('bind_', arguments); 
      if (this.$n().className.indexOf("nodrag") > -1) { 
       this.domListen_(this.$n(), "onDragstart", function(event) { 
        event.stop(); 
        return false; 
       }); 
      } 
      if (this.$n().className.indexOf("nodrop") > -1) { 
       this.domListen_(this.$n(), "onDragover", function(event) { 
        event.stop(); 
       }); 
      } 
     } 
    }); 
}); 

이 ZK 사용하여이를 적용하는 방법에 집중한다, 그러나 사실은 그냥 일반 자바 스크립트입니다. 자세한 내용은 여기를 참조하십시오. disable text drag and drop