gpt4 book ai didi

javascript - 2个剪贴板的JS重置功能

转载 作者:行者123 更新时间:2023-11-28 03:43:08 27 4
gpt4 key购买 nike

美好的一天,我想请教一些建议,我对 html 和 css 以及 java 真的很陌生,将它们放在一起对我来说有点困难,所以我希望得到一些建议。

我最近创建了一个表单,但我不知道如何重置所有功能,比如在完成复制后将包含重置为其原始表单。

请提供我的代码,让我知道我能做什么。非常感谢您的帮助。

<html>
<head>
<style type="text/css">
/* Some Generic styles */
body {
text-align: center;
font-family: "Open Sans", Helvetica, Arial, sans-serif;
color: #023378;
line-height: 0.5;
background-color:#1E334F;
}
h1 {
margin: 0.5em auto 0.5em;
color: #71A4EB;
}
textarea,
button {
font-size: 1em;
font-family: "Open Sans", Helvetica, Arial, sans-serif;
}
textarea {
display: block;
margin: 0.5em auto 0.5em;
background: #CAD6E6;
resize: vertical;
}
[id="cleared"] {
margin-top: 4em;
}
textarea:focus {
border-color: #8fa423;
}
button {
position: relative;
padding: 8px 20px;
border: 0;
font-size: 0.835em;
text-transform: uppercase;
letter-spacing: 0.125em;
font-weight: bold;
color: #3F71B6;
background: #7DA9E6;
transition: background .275s;
}
button:hover,
button:focus {
background: #5275A5;
}

p {
margin-top: 3.25em;
font-size: .825em;
color: #777;
font-weight: bold;
letter-spacing: .01em
}
</style>

<h1>SH!N</h1>
<body>

<textarea id="to-copy" cols="80" rows="25" spellcheck="false">
SESA
Caller's Name:
Call back number:
Email Address:
Related case #s (case history):
Location, remote/hotel/office:

Application Name:
Number of Users Affected: Number of Users Affected: (Single User / Less than 5 users / 5 or more users)

What is the issue/problem:
When did the issue/problem begin:
Login id:
Error message (if any):
When was the last time it worked properly:
Have there been any changes to your PC since the last time it worked properly:
Have you changed your password recently:

Troubleshooting steps (detailed):

Additional Detail (links, screen shots etc.. :
</textarea><br>

<button id="copy" type="button">Copy<span class="copiedtext"aria-hidden="true"></span></button>
<textarea id="text" cols="80" rows="8" >
Resolution:


A - problem:
B - cause:
C - actions:
D - resolution:
</textarea><br>
<button onclick="copy()">Copy</button><br>

<SCRIPT TYPE="text/javascript">
var toCopy = document.getElementById( 'to-copy' ),
btnCopy = document.getElementById( 'copy' );

btnCopy.addEventListener( 'click', function(){
toCopy.select();

if ( document.execCommand( 'copy' ) ) {
btnCopy.classList.add( 'copied' );

var temp = setInterval( function(){
btnCopy.classList.remove( 'copied' );
clearInterval(temp);
}, 600 );

} else {
console.info( 'document.execCommand went wrong…' )
}

return false;
} );

function copy () {
var text = document.getElementById('text');
var range = document.createRange();

range.selectNode(text);
window.getSelection().addRange(range);
document.execCommand('copy');
}

</SCRIPT>


</body>
</html>

最佳答案

为了制作表单,您不应该使用 textarea(或仅将其用作表单的一部分,例如在博客中发表评论)

如果要制作表单,必须使用表单标签

   <form id="myForm">Caller's name <input type="text" name="callerName"> ...  </form>

https://www.w3schools.com/html/html_forms.asp

然后如果你想重置它,在 javascript 中:

document.getElementById("myForm").reset();

您的表单确实有 id“myForm”,您选择此元素并在其上使用 reset() 函数,该函数在表单上起作用。

PS:你应该把你的样式放在一个 CSS 文件中,你的脚本放在一个 JS 文件中。

编辑:

如果你想复制它:

var myForm = document.getElementById('myForm');
var targetForm = document.getElementById('targetForm');
targetForm.innerHTML = myForm.innerHTML;

当然,您需要将 id 设置为 targetForm 的表单标签。

关于javascript - 2个剪贴板的JS重置功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44113333/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com