Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么我的;“复制到剪贴板”;按钮不工作?_Javascript_Html - Fatal编程技术网

Javascript 为什么我的;“复制到剪贴板”;按钮不工作?

Javascript 为什么我的;“复制到剪贴板”;按钮不工作?,javascript,html,Javascript,Html,对网络编程来说是个新手。我尝试过重新创建一些网站,我想实现一个“复制到剪贴板”按钮,但它不起作用,我不知道为什么。我搜索了Stackoverflow,但找不到这个问题的答案 提前感谢您的帮助 HTML: <!DOCTYPE html> <html lang='en'> <head> <meta charset='UTF-8'> <title>Portfolio Homepage</title>

对网络编程来说是个新手。我尝试过重新创建一些网站,我想实现一个“复制到剪贴板”按钮,但它不起作用,我不知道为什么。我搜索了Stackoverflow,但找不到这个问题的答案

提前感谢您的帮助

HTML

<!DOCTYPE html>
  <html lang='en'>    
  <head>
    <meta charset='UTF-8'>
    <title>Portfolio Homepage</title>
    <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
    <link rel="stylesheet" href="styles.css">
  </head>

  <body>
    <div class="container">
      <div class="nav-wrapper">
        <div class="left-side">
          <div class="nav-link-wrapper">
            <a href="index.html">Home</a>
          </div>
  
          <div class="nav-link-wrapper active-nav-link">
            <a href="about.html">About</a>
          </div>
        </div>
        <div class="right-side">
          <div class="brand">
            ptp
          </div>
        </div>
      </div>
      <div class="content-wrapper">
        <div class="two-column-wrapper">
          <div class="profile-image-wrapper">
            <img src="images/profile.jpg" alt="">
          </div>
          <div class="profile-content-wrapper">
            <h1>Managemt and Additional Information</h1>
            <p>This is a student's non-profit project made solemnly for practice and community   involvement. If you have any further inquiry about this project, please contact placeholdermail. </p>
            <p>Thank you very much!</p>
          </div>
        </div>
      </div>
    </div>
 </body>
</html>
function copythis() {
   var copyText = document.getElementById("myInput");
   copyText.select(); 
   copyText.setSelectionRange(0, 99999); /*For mobile devices*/

   /* Copy the text inside the text field */
   document.execCommand("copy");

   /* Alert the copied text */
   alert("Copied the text: " + copyText.value);
}

我看到您一直在尝试从

现在,您的代码中有什么错误: 您尚未在
HTML
中定义
myInput
,以便它可以从HTML DOM中提取文本。
下面是工作代码

函数myFunction(){
var copyText=document.getElementById(“myInput”);
copyText.select();
copyText.setSelectionRange(0,99999);/*用于移动设备*/
/*复制文本字段内的文本*/
文件。执行命令(“副本”);
/*警告复制的文本*/
警报(“复制的文本:+copyText.value”);
}

投资组合主页
ptp
管理和附加信息
这是一个学生的非营利项目,庄严地进行实践和社区参与。如果您对此项目有任何进一步的疑问,请通过电子邮件联系我们。

复制文本

多谢各位


您的输入在哪里?在HTML上,还需要关注输入:
textArea.focus()
textArea.select()是否尝试将链接复制到访问者所在的当前页面?