0

我正在研究剪贴板功能...

我正面临鼠标事件问题...在下面的代码中,当我删除label tagand 时style="display:none" class="hide",我的剪贴板功能正常工作,但剪贴板功能不工作..

请检查以下代码:我需要进行哪些更改才能使其完美运行?

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Copy to Clipboard with ZeroClipboard, Flash 10 and jQuery</title>
    <link href="_assets/css/Style.css" rel="stylesheet" type="text/css" />

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script>

    <script src="_assets/js/ZeroClipboard.js" type="text/javascript"></script>

    <script type="text/javascript">


function myfunc2() {
 var selectedobj=document.getElementById('texter');

  if(selectedobj.className=='hide'){  //check if classname is hide 
    selectedobj.style.display = "block";
    selectedobj.readOnly=true;
    selectedobj.className ='show';
  }else{
    selectedobj.style.display = "none";
    selectedobj.className ='hide';
 }
}


    </script>


<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());
 });
});


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

</head>
<body>


    <label  onmouseover="myfunc2()">Click here</label> 

<textarea name="texter" id="texter"  style="display:none" class="hide"   readonly>sdfdsfsdfgdfdfg</textarea>
<input type="button" value="Copy to clipboard" id="copy-button" />



</body>
</html>
4

0 回答 0