기본 블로깅 플랫폼을 작성하려고합니다. 사용자에게 미리 블록 내의 코드를 클립 보드에 복사 할 수있는 기능을 제공하고 싶습니다.새로 삽입 된 요소에 ZeroClipboard 클립을 어떻게 붙일 수 있습니까?
나는 이것을 달성하기 위해 ZeroClipboard을 사용하고 있습니다. 문서가 여기에 클립 보드 항목을 추가하는 페이지의 각 pre
을 통해, I 루프, 준비되면 다음과 같이
$(document).ready(function() {
ZeroClipboard.setMoviePath('ZeroClipboard/ZeroClipboard.swf');
var preNum = 1
$('pre').each(function() {
// Get a unique id for the element I will be inserting
var id = 'copy-btn-' + preNum++
// Capture the text to be copied to the clipboard
var text = $(this).text()
// Insert the element, just before this
$('<div class="copy-btn" id="' + id + '-cont"><i class="icon-file icon-white" id="' + id + '"></i></div>').insertBefore(this)
// Capture the newly inserted element
var elem = $(this).prev()
// Create the clip, and glue it to the element
var clip = new ZeroClipboard.Client();
clip.setText(text)
clip.glue(elem)
})
});
나는이 작업을 수행하려고하면 자바 스크립트 콘솔 보고서 : Uncaught TypeError: Cannot read property 'zIndex' of undefined
나의 현재를 문제의 이해는 클립을 접착제로 붙이려고 할 때 삽입 된 요소가 아직 dom에서 사용 가능하지 않기 때문에 접착제가 전혀 사용되지 않는 이유입니다.
아무도 내가 이것을 성취 할 수 있을지 모른다. Gluing instructions 가입일
그레이트 콜. 도와 주셔서 감사합니다. – finiteloop