简体   繁体   English

Javascript-将字符添加到网页特定字段中的现有字符串作为客户端

[英]Javascript - add a character to existing string in specific field of web page as a client

Need modification of existing code below, which currently copying from that field, to instead keep the string of characters that is already there AND add a character to the beginning of that string, ie result should be "X ABC", where X is added character and ABC existing string. 需要修改下面现有的代码(当前从该字段复制),以保留已存在的字符串并在该字符串的开头添加一个字符,即结果应为“ X ABC”,其中添加X和ABC现有的字符串。 I am using that web page as a client. 我正在将该网页用作客户端。

 javascript:(function() { var copyText = document.getElementById("mergeFields-input-text"); copyText.select(); document.execCommand("Copy"); tempAlert("COPIED SUBJECT", 500); function tempAlert(msg, duration) { var el = document.createElement("div"); el.setAttribute("style","position:absolute;top:1%;left:35%;background-color:white;"); el.innerHTML = msg; document.body.appendChild(el); setTimeout(function(){ el.parentNode.removeChild(el); }, duration ); } })(); 

I'm not going to modify your code because it's not really relevant to the question at hand. 我不会修改您的代码,因为它与手头的问题无关。

Here's how you can combine two strings: 这是组合两个字符串的方法:

Assuming your variable msg is abc 假设您的变量msgabc

let prefix = 'X';
El.innerHTML = `${prefix} ${msg}`;

Should result in X abc 应该导致X abc

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

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