2017-11-11 105 views

回答

0

您可以使用javascript來禁止拖動某些組件的文本。有幾種方法來應用這些代碼組成部分,他下使用一個的sclass作爲標記,這是相當方便的,如果你只需要對少量的文本框:

<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> 

你也可以做到這一點通過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,但實際上它只是普通的javascript。你可以在這裏閱讀更多信息:disable text drag and drop