I have a small script that shall redirect to another page when return is pressed in a textbox, it works fine in IE, Chrome, Safari but not in FireFox. If i attatch the Debugger in FireBug it works.
here is my script:
<form name="form1" method="post" action="Default2.aspx" id="form1">
<input id="ind" onkeydown="defaultButton(event)" />
<script type="text/javascript">
function defaultButton(event) {
if (event.keyCode == 13) {
event.returnValue = false;
event.cancel = true;
Send();
开发者_开发技巧 }
}
function Send() {
var content = document.getElementById("ind").value;
if (content == null || content.length == 0) {
document.getElementById("ind").focus();
return;
} else {
window.location = "http://www.google.com?name=" + content;
}
}
</script>
Is thre anybody there can help med get this working cross browser? Thank very much in advance!!
You can try calling preventDefault
function defaultButton(event) {
if (event.keyCode == 13) {
event.returnValue = false;
if (event.preventDefault) {
event.preventDefault();
}
Send();
}
}
精彩评论