I know how can we use onkeyup
event of an element...
Is there a function that already exists in Javascript to do this? Should I create a function to do this? Or should I put alert code (with nested if statements开发者_StackOverflow) in Javascript area code without using a function?
That was my #1 question..My #2 question is:
I know differences about key events in IE and Firefox and ... (keycode and charcode and ...) What is the best way for using key events for IE and Firefox for detecting upper situation that I explained?
Answer to you first question :
more about keystrokes : Detecting keystrokes
Example to disable enterkey on press
<script type="text/javascript">
function stopRKey(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}
document.onkeypress = stopRKey;
</script>
2. Question:
With this script you can detect upper/lower case:
<script type="text/javascript">
function isUpper(String)
{
if(String.charCodeAt(0) > 64 && String.charCodeAt(0) < 91)
return true;
else
return false;
}
if(isUpper("A"))
alert("upper case");
else
alert("lower case");
</script>
精彩评论