我有这两个功能:
function myFunction() {
var x = document.getElementById("myTextarea").value;
document.getElementById("demo").innerHTML = x;
}
function myFunction1() {
var x = document.getElementById("myTextarea1").value;
document.getElementById("demo1").innerHTML = x;
}
我没有成功将它们合并为一个函数。
function myFunction(inputId,targetId) {
var x = document.getElementById(inputId).value;
document.getElementById(targetId).innerHTML = x;
}
myFunction('myTextarea','demo');
myFunction('myTextarea1','demo1');
你的意思是:
function myFunction() {
var textArea = document.getElementById("myTextarea").value;
var textArea1 = document.getElementById("myTextarea1").value;
document.getElementById("demo").innerHTML = textArea;
document.getElementById("demo1").innerHTML = textArea1;
}
insertValue('Value','Inner')这是一个获得2个参数的函数,first-value id和second inner id。您可以输入任何ID并使用此多用途功能
function insertValue(id_value, id_inner) {
let x = document.getElementById(id_value).value;
document.getElementById(id_inner).innerHTML = x;
}
insertValue('Value','Inner');
<input id="Value" type="" name="" value="value which you want to put">
<div id="Inner">inner text which you will dont see</div>