简体   繁体   中英

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. 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

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

Should result in X abc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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