繁体   English   中英

用于chrome的html复制命令可复制多个文本框

[英]Copy command in html for chrome to copy multiple text boxes

我正在创建一个记事本,以帮助使用户之间的注释保持一致。 我无法将多个文本框复制到字符串。 我已经附上了我所有的Java脚本。

我想用来将多个文本框链接到一个文本字符串中的复制按钮。 重置按钮可用于清除页面,复制按钮可用于检查非空文本框。 请帮助我将复制字符串复制到剪贴板。

我在Java脚本上尝试了很多不同的站点,但均未成功。 我也查看了Stack Overflow,以查看是否可以找到一个关闭的项目。

input type="button" id="BtnSupSubmit" value="Copy" onclick="notEmptySup()" style="width: 87px"
  function settime() {
    var curtime = new Date();
    var curhour = curtime.getHours();
    var curmin = curtime.getMinutes();
    var time = "";

    if (curhour == 0) curhour = 12;
    time = (curhour > 12 ? curhour - 12 : curhour) + ":" +
     (curmin < 10 ? "0" : "") + curmin + ":" +
     (curhour > 12 ? "PM" : "AM");

    document.date.clock.value = time;
    clock = time
    window.status = time
}

function notEmptySup() {
    var myTextField = document.getElementById('TxtBoxCallersName');
    if (myTextField.value != "") notEmptySup2()
    else
        alert("Please enter callers name.")
}
function notEmptySup2() {
    var myTextField = document.getElementById('TxtBoxSupIssue');
    if (myTextField.value != "") notEmptySup3()
    else
        alert("Please enter the reason for the escalation.")
}
function notEmptySup3() {
    var myTextField = document.getElementById('TxtBoxSupAction');
    if (myTextField.value != "") notEmptySup4()
    else
        alert("Please enter the action you took to help the customer.")
}
function notEmptySup4() {
    var myTextField = document.getElementById('TxtBoxSupResolution');
    if (myTextField.value != "") CreateMessage()
    else
        alert("Please enter the resolution of the call.")
}
    function CreateMessage() {

    strMessage =
        "Time: " + clock + "\|" +
        "***Supervisor Escalation" + "\***|" +
        "Caller: " + document.getElementById("TxtBoxCallersName").value + " \| " +
        "Reason: " + document.getElementById("TxtBoxSupIssue").value + " \| " +
        "Action: " + document.getElementById("TxtBoxSupAction").value + " \| " +
        "Resolution: " + document.getElementById("TxtBoxSupResolution").value + " \| " +
        "Ticket Number: " + document.getElementById("TxtBoxSupTicketNumber").value + " \| " +
        "Addl Notes: " + document.getElementById("TxtBoxSupNotes").value;


        document.getElementById("hdnBuffer").value = strMessage;

        var buffer = document.getElementById("hdnBuffer").createTextRange();
        buffer.execCommand("Copy");
    }

您拥有的大部分都是多余的。 请参阅下面的内联评论:

 // Get a reference to the form let frm = document.querySelector("form") // Set up a sumbit event handler for the form frm.addEventListener("submit", function(evt){ // Just get the locally formatted time var message = "Time: " + new Date().toLocaleTimeString() + "\\n***Supervisor Escalation***\\n\\n"; // Get all the input elements let inputs = document.querySelectorAll("input"); // Loop over them for(let i = 0; i < inputs.length; i++){ if(inputs[i].value === ""){ alert("Please enter the " + inputs[i].dataset.message); inputs[i].focus(); // Put focus on bad element evt.preventDefault(); // Cancel the form submit break; // Exit the loop } else { // Update the message message += inputs[i].dataset.message + ": " + inputs[i].value + " \\n"; } } alert(message); // Do whatever you want with the message }); 
 <form action="https://example.com" method="post"> <div><label>Name:<input data-message="callers name"></label></div> <div><label>Issue: <input data-message="reason for the escalation"></label></div> <div><label>Action: <input data-message="action you took to help the customer"></label></div> <div><label>Resolution: <input data-message="resolution of the call"></label></div> <button type="submit">Submit Ticket</button> </form> 

暂无
暂无

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

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