Execute function when enter is pressed if textbox has focus
Is it possible to execute a funct开发者_运维问答ion by pressing the enter key on the keyboard only if a certain textbox has focus. i.e. if any other textbox has focus or no textbox has focus, the enter key should do nothing.
$('#myTextbox').bind('keyup', function(e) {
if ( e.keyCode === 13 ) { // 13 is enter key
// Execute code here.
}
});
$(function(){
$("#textarea").keyup(function(e){
if (e.keyCode === 13) {
//do stuff
}
});
});
Enter any thing in Text box then press Enter to execute
<form onSubmit='alerttest(this); return false'>
<input type="text">
</form>
<script language="javascript">
function alerttest()
{
alert("Executing jolly.exe !!!!");
// function edited by Inderpreet singh
}
</script>
精彩评论