2014-09-17 1 views
0

javascript가 클립 보드에 직접 액세스 할 수 없기 때문에 div의 텍스트를 복사하는 내 웹 사이트에 복사 버튼을 갖고 싶습니다. 그 zclip하지만, 숨겨진 요소에 zclip을 바인딩 할 때 zclip보다 그 요소를 보여 주거나 작동하지 않는다면 저를 도와주세요.숨겨진 요소에 바인딩 할 때 zclip이 작동하지 않습니다.

HTML 코드 :

<span class="homebutton">Get code for this theme</span> 
<div class="get_code"> 
    <pre class="theme_code"><?php echo $theme['theme_code'];?></pre> 
    <div class="copy_code">Copy</div> 
</div> 

jQuery를 코드 : 사전에

$('.homebutton').click(function(){ 
    $('.get_code').show('slow'); 
}); 

$('.copy_code').zclip({ 
    path: "js/ZeroClipboard.swf", 
    copy: function(){return $('.theme_code').text();}, 
    afterCopy: function() {} 
}); 

감사합니다! 내가 필요에 따라

+0

다음과 함께 표시되도록는'.show()는'한 다음에'zclip'를 초기화. –

+0

나는 그것을 시도했지만 나를 위해 일하지 않았다. 시간을 내 주셔서 감사합니다. –

답변

0

나는 내가의 setTimeout 기능에 이벤트를 바인딩을 시도 솔루션을 가지고 있으며 일 ... :)

내가 그 코드를 공유하고있어 그것이 다른 사람을 도움이되기를 바랍니다!

HTML 코드 :

<span class="homebutton">Get code for this theme</span> 
<div class="get_code"> 
    <pre class="theme_code"><?php echo $theme['theme_code'];?></pre> 
    <div class="copy_code">Copy</div> 
</div> 

jQuery를 코드 : 그것의 숨겨진 필드와 함께 작동하지 않는 경우

$('.homebutton').click(function(){ 
    $('.get_code').show('slow'); 
    setTimeout(function(){bind_zclip();},1000); 
}); 

function bind_zclip() 
{ 
    $('.copy_code').zclip({ 
     path: "js/ZeroClipboard.swf", 
     copy: function(){return $('.theme_code').text();}, 
     afterCopy: function() {} 
    }); 
} 
관련 문제