Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
368 views
in Technique[技术] by (71.8m points)

javascript - html <input type =“text”/> onchange事件无效(html <input type=“text” /> onchange event not working)

I am trying to do some experiment.

(我正在尝试做一些实验。)

What I want to happen is that everytime the user types in something in the textbox, it will be displayed in a dialog box.

(我想要发生的是,每次用户在文本框中键入内容时,它都会显示在对话框中。)

I used the onchange event property to make it happen but it doesn't work.

(我使用onchange事件属性来实现它,但它不起作用。)

I still need to press the submit button to make it work.

(我仍然需要按下提交按钮才能使其正常工作。)

I read about AJAX and I am thinking to learn about this.

(我读到了关于AJAX的内容,我正在考虑了解这一点。)

Do I still need AJAX to make it work or is simple JavaScript enough?

(我是否仍然需要AJAX才能使其工作或简单的JavaScript足够?)

Please help.

(请帮忙。)

(index.php)

<script type="text/javascript" src="javascript.js"> </script>

<form action="index.php" method="get">
 Integer 1: <input type="text" id="num1" name="num1" onchange="checkInput('num1');" /> <br />
 Integer 2: <input type="text" id="num2" name="num2" onchange="checkInput('num2');" /> <br />
 <input type="submit" value="Compute" />
</form>

(javascript.js)

function checkInput(textbox) {
 var textInput = document.getElementById(textbox).value;

 alert(textInput); 
}
  ask by Newbie Coder translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...