简体   繁体   English

回发事件后 javascript 不工作

[英]After a post back event javascript is not working

I am using the below code to copy content to clipboard.我正在使用以下代码将内容复制到剪贴板。 This is for asp.net core.这是针对 asp.net 核心的。 But once a postback happens.但是一旦回发发生。 this code is not working.此代码无效。 What is the issue?问题是什么?

  function copy() {
  var txt = document.getElementById("result");
  navigator.clipboard.writeText(txt.innerText);
}

Well, some browser doesn't support this navigator.clipboard.writeText() , it's kinda like a Mozilla, I'll try make alternate this code for supporting most browsers.好吧,有些浏览器不支持这个navigator.clipboard.writeText() ,它有点像 Mozilla,我会尝试制作替代此代码以支持大多数浏览器。 May help, if it is result of yours will be 'txt' only or copy text only.可能会有所帮助,如果它是您的结果,则将仅为“txt”或仅复制文本。 try this:试试这个:

 <input type="text" id="result" value="This is a text"/> <input type="Button" id="b1" value="Copy Here" onClick="copy()"/> <script> function copy() { /* return content of input field to variable text */ var txt = document.getElementById("result"); /* call function on button click */ txt.select(); document.execCommand("copy"); } </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM