白色 space 将 firefox 与剪贴板 js 一起使用时未删除
White space not removing when using firefox with clipbord js
我正在使用 clipbord.js 当我点击我的按钮并复制代码,然后将其粘贴到顶部留下相当大空隙的地方时
我已经尝试在此处使用 .replace(/\s/g, "")
Codepen Example --> Link 已使用工作代码更新
Question: When use firefox how to make sure that there is no gap when I have copied the code and then go to paste it.
There is no gap when I use Google Chrome, Edge, Internet Explore
$(document).ready(function() {
new Clipboard("#copy-button", {
text: function(trigger) {
var str = $(trigger).parent().find('pre').text();
return str.replace(/\s/g, "");
}
});
});
HTML
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="page-header"><h1>Clean URLs</h1></div>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<div class="panel panel-default">
<div class="panel-heading">
<div class="clearfix">
<div class="pull-left" style="padding-top: 7.5px;">
<h1 class="panel-title">Example 1</h1>
</div>
<div class="pull-right">
<button type="button" id="copy-button" data-clipboard-target="#h1" class="btn btn-primary"><i class="fa fa-clipboard" aria-hidden="true"></i> Copy</button>
</div>
</div>
</div>
<div class="panel-body">
<pre id="h1">
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L,QSA]
</pre>
</div>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<div class="panel panel-default">
<div class="panel-heading">
<div class="clearfix">
<div class="pull-left" style="padding-top: 7.5px;">
<h1 class="panel-title">Example 2</h1>
</div>
<div class="pull-right">
<button type="button" id="copy-button" data-clipboard-target="#h2" class="btn btn-primary"><i class="fa fa-clipboard" aria-hidden="true"></i> Copy</button>
</div>
</div>
</div>
<div class="panel-body">
<pre id="h2">
RewriteEngine On
RewriteBase /root_folder_name/
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond !^(index\.php|images|js|uploads|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L]
</pre>
</div>
</div>
</div>
</div>
</div>
问题是 $(trigger).parent().find('pre').text()
返回了空字符串。所以,我将其修改为 $(trigger).closest('.panel').find('pre').text();
我正在使用 clipbord.js 当我点击我的按钮并复制代码,然后将其粘贴到顶部留下相当大空隙的地方时
我已经尝试在此处使用 .replace(/\s/g, "")
Codepen Example --> Link 已使用工作代码更新
Question: When use firefox how to make sure that there is no gap when I have copied the code and then go to paste it.
There is no gap when I use Google Chrome, Edge, Internet Explore
$(document).ready(function() {
new Clipboard("#copy-button", {
text: function(trigger) {
var str = $(trigger).parent().find('pre').text();
return str.replace(/\s/g, "");
}
});
});
HTML
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="page-header"><h1>Clean URLs</h1></div>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<div class="panel panel-default">
<div class="panel-heading">
<div class="clearfix">
<div class="pull-left" style="padding-top: 7.5px;">
<h1 class="panel-title">Example 1</h1>
</div>
<div class="pull-right">
<button type="button" id="copy-button" data-clipboard-target="#h1" class="btn btn-primary"><i class="fa fa-clipboard" aria-hidden="true"></i> Copy</button>
</div>
</div>
</div>
<div class="panel-body">
<pre id="h1">
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L,QSA]
</pre>
</div>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<div class="panel panel-default">
<div class="panel-heading">
<div class="clearfix">
<div class="pull-left" style="padding-top: 7.5px;">
<h1 class="panel-title">Example 2</h1>
</div>
<div class="pull-right">
<button type="button" id="copy-button" data-clipboard-target="#h2" class="btn btn-primary"><i class="fa fa-clipboard" aria-hidden="true"></i> Copy</button>
</div>
</div>
</div>
<div class="panel-body">
<pre id="h2">
RewriteEngine On
RewriteBase /root_folder_name/
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond !^(index\.php|images|js|uploads|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L]
</pre>
</div>
</div>
</div>
</div>
</div>
问题是 $(trigger).parent().find('pre').text()
返回了空字符串。所以,我将其修改为 $(trigger).closest('.panel').find('pre').text();