admin管理员组文章数量:1277901
I have a text field with an onkeyup
event. But this event is not fired when I select a browser autoComplete value. I have added an onclick event, but it doesn't work.
I have tested many solutions posted on stackoverflow for catching the browse autocoComplete selection, but nothing has resolved this problem.
Try this simple example to see the issue (reproduced on Firefox 3.6, Chrome 10.0 and IE8):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ".dtd">
<html>
<head>
<title>Test</title>
<script type="text/javascript" src=".5.1.min.js"></script>
<script type="text/javascript">
//<![CDATA[
function onkeyupInput(){
$('#divResult').text($('#myInput').val());
}
//]]>
</script>
</head>
<body>
<form name="myForm" action="#">
Tape a value and send it. Then select this value with your browser AutoComplete value :<br />
<input id="myInput" name="myInput" type="text" onkeyup="onkeyupInput();" onclick="onkeyupInput();" value="" />
<input type="submit" />
</form>
Result of onkeypress and onclick :
<div id="divResult"></div>
<br />
<b>The issue : Result of onkeypress and onclick is not update when an autoplete value of a browser is selected.</b>
</body>
</html>
Thanks!
I have a text field with an onkeyup
event. But this event is not fired when I select a browser autoComplete value. I have added an onclick event, but it doesn't work.
I have tested many solutions posted on stackoverflow for catching the browse autocoComplete selection, but nothing has resolved this problem.
Try this simple example to see the issue (reproduced on Firefox 3.6, Chrome 10.0 and IE8):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="http://code.jquery./jquery-1.5.1.min.js"></script>
<script type="text/javascript">
//<![CDATA[
function onkeyupInput(){
$('#divResult').text($('#myInput').val());
}
//]]>
</script>
</head>
<body>
<form name="myForm" action="#">
Tape a value and send it. Then select this value with your browser AutoComplete value :<br />
<input id="myInput" name="myInput" type="text" onkeyup="onkeyupInput();" onclick="onkeyupInput();" value="" />
<input type="submit" />
</form>
Result of onkeypress and onclick :
<div id="divResult"></div>
<br />
<b>The issue : Result of onkeypress and onclick is not update when an autoplete value of a browser is selected.</b>
</body>
</html>
Thanks!
Share Improve this question edited Apr 15, 2013 at 9:12 shrewdbeans 12.5k24 gold badges76 silver badges118 bronze badges asked Mar 25, 2011 at 8:56 remi.gaubertremi.gaubert 4333 silver badges14 bronze badges1 Answer
Reset to default 9Newer browsers support the oninput event:
$(function () {
$('#myInput').on("input",function() {
$('#divResult').text($(this).val());
});
});
<input id="myInput" name="myInput" type="text" value="" />
If you need to support older browsers, try
var tId = "";
function monitor() {
$('#divResult').text($('#myInput').val());
}
$(function () {
$('#myInput')
.focus(function() {
tId=setInterval(monitor,100);
})
.blur(function() {
clearInterval(tId);
});
});
本文标签: inputJavascript detect a selection of browser AutoComplete valueStack Overflow
版权声明:本文标题:input - Javascript detect a selection of browser AutoComplete value - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741266777a2368624.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论