[ gruja10 @ 04.03.2010. 02:31 ] @
| Kako da uhvatim taster enter u Mozili. Sledeci kod radi u Internet Eksploreru ali nece u Mozili. Imam Mozilu verzija 3.5.2
e = window.event;
var key = (e.keyCode) ? e.keyCode : e.which;
if (key == 13)
{
alert("Pritisnut taster enter");
} |
[ Nikola Poša @ 04.03.2010. 09:57 ] @
Evo recimo primer kako se to proverava jQuery-jem, i to prolazi u bilo kom browser-u:
Code:
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<input type = "text" name = "test">
<script>
$("input[name='test']").keydown(function(e) {
if(e.which == 13) {
alert('Pritisnut taster enter.');
}
});
</script>
</body>
</html>
[ gruja10 @ 04.03.2010. 23:10 ] @
Hvala na odgovoru, posluzilo mi je za dalja isprobavanja. Ako neko ne zeli da koristi jQuery evo nasao sam u medjuvremenu kod koji radi na Mozili i Internet Eksploreru, na ostalim pretrazivacima nisam testirao.
<input type="text" onKeyDown="javascript: hvataj(event)">
<script>
function hvataj(e)
{
var intKey = 0;
e = (window.event) ? event : e;
intKey = (e.keyCode) ? e.keyCode : e.charCode;
if (intKey == 13)
{
alert("Pritisnut taster enter");
}
}
</script>
Copyright (C) 2001-2025 by www.elitesecurity.org. All rights reserved.