2010-05-13 6 views
0

Zeroclipboard을 사용하여 클립 보드에 물건을 복사하려고하는데 작동하지 않는 것 같습니다. 내 코드 :ZeroClipboard 관련 문제

HTML :

<textarea name="texter" id="texter"></textarea> 
<input type="button" value="Copy to clipboard" id="copy-button" /> 

자바 스크립트 :

<script type="text/javascript"> 
jQuery(document).ready(function(){ 

    var clip = new ZeroClipboard.Client(); 
    clip.setText(''); 

    jQuery('#copy-button').click(function(){ 
    clip.setText(jQuery('#texter').val()); 
} 


}); 
</script> 

이 문제점은 무엇입니까? 탄스크!

답변

4

몇 가지.

먼저 괄호는 약간 꺼져 있습니다. 이 있어야한다 :

jQuery(document).ready(function(){ 

    var clip = new ZeroClipboard.Client(); 
    clip.setText(''); 

    jQuery('#copy-button').click(function(){ 
    clip.setText(jQuery('#texter').val()); 
}); 
}); 

하지만 그 문제가 해결되지 않습니다.

ZeroClipBoard instructions

에 당신이 '접착제'에 필요하거나 페이지에 DOM 요소에 플래시 동영상을 링크를 참조하십시오. 복사 된 텍스트가 저장됩니다. 그런 다음 jQuery를 클릭 이벤트에 사용할 수 없거나 문서를 오해 할 수는 있지만 mousedown 이벤트를 버튼에 등록하고 클립에 바인딩 할 수 있습니다.

코드에 적용하십시오.

<script type="text/javascript"> 
     $(document).ready(function() { 
      var clip = new ZeroClipboard.Client(); 

      clip.setText(''); // will be set later on mouseDown 

      clip.addEventListener('mouseDown', function (client) { 
       // set text to copy here 
       clip.setText(jQuery('#texter').val()); 

       // alert("mouse down"); 
      }); 

      clip.glue('copy-button'); 
     }); 
</script> 

이렇게하면됩니다.

이 예제를 jQuery없이 완전히 사용할 수 있지만 문서가 준비되어 있으면 DOM 준비가 완료된 후에 만 ​​실행되도록 만드는 것이 좋습니다. 또한 getElementById 대신 jQuery를 사용합니다.

희망이 있습니다.

0
<!-- <script type="text/javascript" src="http://davidwalsh.name/demo/ZeroClipboard.js"></script> --> 
    function copyText(fieldName,buttonName){ 
     var fieldNameTemp =fieldName; 
     var buttonNameTemp =buttonName; 
     var val = ""; 
     try{ 
      val = navigator.userAgent.toLowerCase(); 
     }catch(e){} 
     var swfurl = "js/ZeroClipboard.swf"; 
     setTimeout(function() { 
      ZeroClipboard.setMoviePath(swfurl); 
      var clip = new ZeroClipboard.Client(); 
      clip.addEventListener('mousedown', function() { 
       clip.setText(document.getElementById(fieldNameTemp).value); 
      }); 
      clip.addEventListener('complete', function (client, text) { 
       try{ 
        if(val.indexOf("opera") > -1 || val.indexOf("msie") > -1 || val.indexOf("safari") > -1 || val.indexOf("chrome") > -1){ 
         alert('Your text has been copied'); 
        } 
       }catch(e){ 
        alert('Please alert: not use on fireFox'); 
       } 
      }); 
      clip.glue(buttonNameTemp); 
     }, 2000); 
    }