2017-11-11 101 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