<html>
<body>
<input type = "text" id = "to" οnkeydοwn="check(event)" OnBlur="replaceNum(this)">
<button type = "button" οnclick="document.getElementById('to1').innerHTML = String.fromCharCode(190)">Click me to display</button>
<p id="to1"></p>
<script type = text/javascript>
function check(evt)
{
//var keycode = evt.keyCode;
//alert(keycode);
//alert(String.fromCharCode(あ)) // => "å"全ての半角
alert(String.fromCharCode(190)) // => "¾"
alert(String.fromCharCode(evt.keyCode));
alert(evt.keyCode);
alert(KeyboardEvent);
var k = evt.keyCode;
// 0~9, テンキ―0~9, backspace, tab, delete, →, ←, 以外は入力キャンセル
if(!((k >= 48 && k <= 57) || (k >= 96 && k <= 105) || k == 8 || k == 9 || k == 46 || k == 39 || k == 37)) {
//return false;
alert(k);
alert("test1")
alert(String.fromCharCode(k))/*.subString()*/;
// text.value = text.value.replace(/[^0-9]+/i,'');
alert("test")
}
}
function replaceNum(txt) {
txt.value = txt.value.replace(/\D/g,"");
}
</script>
</body>
</html>
<body>
<input type = "text" id = "to" οnkeydοwn="check(event)" OnBlur="replaceNum(this)">
<button type = "button" οnclick="document.getElementById('to1').innerHTML = String.fromCharCode(190)">Click me to display</button>
<p id="to1"></p>
<script type = text/javascript>
function check(evt)
{
//var keycode = evt.keyCode;
//alert(keycode);
//alert(String.fromCharCode(あ)) // => "å"全ての半角
alert(String.fromCharCode(190)) // => "¾"
alert(String.fromCharCode(evt.keyCode));
alert(evt.keyCode);
alert(KeyboardEvent);
var k = evt.keyCode;
// 0~9, テンキ―0~9, backspace, tab, delete, →, ←, 以外は入力キャンセル
if(!((k >= 48 && k <= 57) || (k >= 96 && k <= 105) || k == 8 || k == 9 || k == 46 || k == 39 || k == 37)) {
//return false;
alert(k);
alert("test1")
alert(String.fromCharCode(k))/*.subString()*/;
// text.value = text.value.replace(/[^0-9]+/i,'');
alert("test")
}
}
function replaceNum(txt) {
txt.value = txt.value.replace(/\D/g,"");
}
</script>
</body>
</html>