[英]On typing/entering data in text box getting the entered value to display
I have a text box, after entering which i need to get that value and display in alert box,without using any forms or buttons. 我有一个文本框,输入后,我需要获取该值并显示在警报框中,而无需使用任何表单或按钮。
This is what I used: But its not working ,it gives null value on loading of the file. 这就是我使用的:但是它不起作用,它在加载文件时给出了空值。
HTML 的HTML
<tr>
<td><br>Address of Patient</td>
<td> <br> <input type="text" name="inc_patientAddress" id="inc_address" required></td>
</tr>
Jvascript 脚本
<script type="text/javascript">
var x = document.getElementById('inc_address');
alert(x.value);
</script>
I want to display the text box value after entering the data in text box , Is it possible? 我想在文本框中输入数据后显示文本框值,可以吗? Please help 请帮忙
Use blur
event: 使用blur
事件:
document.getElementById('inc_address').addEventListener('blur', function() {
console.log(this.value);
}, false);
Demo: http://jsfiddle.net/tusharj/hop3szu4/ 演示: http : //jsfiddle.net/tusharj/hop3szu4/
Docs: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener 文件: https : //developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
Try this 尝试这个
For every input 对于每个输入
$('#inc_address').on('input', function() {
alert($(this).val());
});
For every complete Input 对于每个完整的输入
$('#inc_address').on('change', function() {
alert($(this).val());
});
You need to add blur function for that input. 您需要为该输入添加模糊功能。 As soon as it will lost focus from that text box it will call this function and so the alert will be displayed. 一旦它从该文本框中失去焦点,它将调用此函数,因此将显示警报。
<input type="text" name="inc_patientAddress" id="inc_address" onblur="myFunction()" required>
Call this funtion on blur: 将此函数称为模糊:
myFunction(){
alert("#inc_address").value();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.