这是我用来显示一些数据的代码。在这段代码中,我有锚标签,我想在点击它时复制该锚标签的链接。这是我使用的代码如下:
<div class="search_item_list clearfix" id="response">
<?php foreach($jobs as $job){
?>
<a class="copy_text" data-toggle="tooltip" title="Copy to Clipboard"
href="<?=base_url().'home/company_profile_detail?id='.$job['company_id'];?>"><span class="icon link"><i class="fa fa-link"></i></span>Copy Link</a>
<?php } ?>
</div>
<script>
$(".copy_text").click(function(e){
e.preventDefault();
var button = $(this);
var text = button.attr("href");
text.select();
$(document).execCommand("copy");
alert("Copied the text ");
})
</script>
Run Code Online (Sandbox Code Playgroud)
我得到 jQuery 作为
text.select 不是函数。
jquery ×1