zClip - 仅复制可见文本

时间:2014-09-27 14:36:14

标签: javascript jquery zclip

嘿希望这是一个简单的解决方案:

点击按钮,我希望只能复制id ="描述"中可见的文字。我做错了什么?

HTML:

<p id="description"> Test <span style="display:none">test2</span></p>
<button type="button" id="copy-description">Click Me!</button>

jQuery的:

<script type="text/javascript" src="js/jquery.zclip.js"></script>
<script type="text/javascript">
$(document).ready(function(){

$('#copy-description').zclip({
    path:'js/ZeroClipboard.swf',
    copy:$('p#description').text()
});

// The link with ID "copy-description" will copy
// the text of the paragraph with ID "description"


$('a#copy-dynamic').zclip({
    path:'js/ZeroClipboard.swf',
    copy:function(){return $('input#dynamic').val();}
});

// The link with ID "copy-dynamic" will copy the current value
// of a dynamically changing input with the ID "dynamic"

});

</script>

1 个答案:

答案 0 :(得分:0)

它必须位于父标记中,如p标记,然后调用该标记内的可见范围。

HTML:

 <p id="description">
    <span id=""> Test </span>
    <span style="display:none; visibility:hidden;">test2</span>
</p>

jQuery的:

$('#copy-description').zclip({
    path:'js/ZeroClipboard.swf',
    copy:$('#description span:visible').text()
});