简体   繁体   English

如何将innerhtml值用作用户输入

[英]how to make innerhtml values as user inputs

I am trying to get the innerElement to a value that is entered by the user but it give me errors. 我正在尝试将innerElement设置为用户输入的值,但它给我错误。 Codes are as above please help 代码如上,请帮助

*****Codes***** *****代码*****

var abc= document.getElementById("searchbar").innerHTML = "Singapore Polytechnic"; --instead of Singapore Polytechnic I want it to be some values that was entered by the users.--

      document.getElementById("searchbar").contentEditable = "true";

      var test = abc;

Try the following: 请尝试以下操作:

 function changeVal(ele){ document.getElementById("searchbar").innerHTML = ele.value; } 
 <p id="searchbar">Test</p> <input value="Hit enter to change value" id="val" onchange="changeVal(this)"> 

I have no plan what the point of your question is but maybe you look for this... 我没有计划要问的问题是什么,但也许您正在寻找...

var foo = document.getElementById('id_of_input_field').value; // get
document.getElementById('id_of_input_field').value = 'value to set'; // set

I think this is what you are looking for 我想这就是你要找的

Code

<input value="variable" id="val" onchange="changeVal(this)">

TS TS

onchange(this){
    let var  = event.target.getElementsByTagName('input').value;
}

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

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