如何在输入标签中使用javasript显示实时输入?(How to show real time input using javascript in input tag?)

我怎样才能使这个脚本运行通过替换textarea标记与输入标记? 我在我的页面中使用了输入标签,并希望添加此代码,但此代码使用了textarea。 如果我更改textarea输入代码不起作用。

function setFontText(text) {
  document.getElementById("Courier_new").innerHTML = text;
  document.getElementById("Arial_Black").innerHTML = text;
} 
  
<textarea id="textField0" autocomplete="off" style="font-family:'Alex Brush';" onkeyup="javascript:setFontText(this.value);" rows="2" name="textField0"></textarea> Multiple text area:

<textarea id="Courier_new" class="fontTextArea2" style="font-family:Courier;" autocomplete="off" name="Courier new"></textarea>

<textarea id="Arial_Black" class="fontTextArea2" style="font-family:Arial; " autocomplete="off" name="Arial Black"></textarea> 
  
 

How can I make this script run by replacing textarea tag with input tag? I used input tag in my page and wanna add this code but this code used textarea. if I change textarea to input the code doesn't work.

function setFontText(text) {
  document.getElementById("Courier_new").innerHTML = text;
  document.getElementById("Arial_Black").innerHTML = text;
} 
  
<textarea id="textField0" autocomplete="off" style="font-family:'Alex Brush';" onkeyup="javascript:setFontText(this.value);" rows="2" name="textField0"></textarea> Multiple text area:

<textarea id="Courier_new" class="fontTextArea2" style="font-family:Courier;" autocomplete="off" name="Courier new"></textarea>

<textarea id="Arial_Black" class="fontTextArea2" style="font-family:Arial; " autocomplete="off" name="Arial Black"></textarea> 
  
 

最满意答案

尝试这个:-

function setFontText(text) { document.getElementById("Courier_new").value = text; document.getElementById("Arial_Black").value = text; }

或者,使用document.getElementsByClassName

方法.getElementsByClassName()返回一个类似数组的对象,所以你必须访问第一个元素(如果有的话)。

var elements = document.getElementsByClassName("anyclass); var value = elements[0].value; alert(value); // 1

或者,您也可以使用.querySelector()方法:

var value = document.querySelector('.anyclass').value; alert(value); // 1

Try this:-

function setFontText(text) { document.getElementById("Courier_new").value = text; document.getElementById("Arial_Black").value = text; }

Or, Using document.getElementsByClassName

The method .getElementsByClassName() returns an array-like object of elements.so you have to access first element (if there is any).

var elements = document.getElementsByClassName("anyclass); var value = elements[0].value; alert(value); // 1

or, you could also use the .querySelector() method:

var value = document.querySelector('.anyclass').value; alert(value); // 1如何在输入标签中使用javasript显示实时输入?(How to show real time input using javascript in input tag?)

我怎样才能使这个脚本运行通过替换textarea标记与输入标记? 我在我的页面中使用了输入标签,并希望添加此代码,但此代码使用了textarea。 如果我更改textarea输入代码不起作用。

function setFontText(text) {
  document.getElementById("Courier_new").innerHTML = text;
  document.getElementById("Arial_Black").innerHTML = text;
} 
  
<textarea id="textField0" autocomplete="off" style="font-family:'Alex Brush';" onkeyup="javascript:setFontText(this.value);" rows="2" name="textField0"></textarea> Multiple text area:

<textarea id="Courier_new" class="fontTextArea2" style="font-family:Courier;" autocomplete="off" name="Courier new"></textarea>

<textarea id="Arial_Black" class="fontTextArea2" style="font-family:Arial; " autocomplete="off" name="Arial Black"></textarea> 
  
 

How can I make this script run by replacing textarea tag with input tag? I used input tag in my page and wanna add this code but this code used textarea. if I change textarea to input the code doesn't work.

function setFontText(text) {
  document.getElementById("Courier_new").innerHTML = text;
  document.getElementById("Arial_Black").innerHTML = text;
} 
  
<textarea id="textField0" autocomplete="off" style="font-family:'Alex Brush';" onkeyup="javascript:setFontText(this.value);" rows="2" name="textField0"></textarea> Multiple text area:

<textarea id="Courier_new" class="fontTextArea2" style="font-family:Courier;" autocomplete="off" name="Courier new"></textarea>

<textarea id="Arial_Black" class="fontTextArea2" style="font-family:Arial; " autocomplete="off" name="Arial Black"></textarea> 
  
 

最满意答案

尝试这个:-

function setFontText(text) { document.getElementById("Courier_new").value = text; document.getElementById("Arial_Black").value = text; }

或者,使用document.getElementsByClassName

方法.getElementsByClassName()返回一个类似数组的对象,所以你必须访问第一个元素(如果有的话)。

var elements = document.getElementsByClassName("anyclass); var value = elements[0].value; alert(value); // 1

或者,您也可以使用.querySelector()方法:

var value = document.querySelector('.anyclass').value; alert(value); // 1

Try this:-

function setFontText(text) { document.getElementById("Courier_new").value = text; document.getElementById("Arial_Black").value = text; }

Or, Using document.getElementsByClassName

The method .getElementsByClassName() returns an array-like object of elements.so you have to access first element (if there is any).

var elements = document.getElementsByClassName("anyclass); var value = elements[0].value; alert(value); // 1

or, you could also use the .querySelector() method:

var value = document.querySelector('.anyclass').value; alert(value); // 1