HTA在enterbutton上打开Internet Explorer [英] HTA opens internet explorer on enterbutton
问题描述
我正在尝试学习HTA的基础知识,但是遇到了问题.
I am trying to learn the basics of HTA but I am running into a problem.
我想要一个带有文本框的HTA GUI,可以将自己的VBScript添加到其中. 当我在文本框中按Enter时,Internet Explorer会打开,并提示我打开/保存HTA文件.
I want a HTA GUI with a text box that I can add my own VBScript to. When I press enter in the text box internet explorer opens and prompts me to open/save the HTA file.
是什么原因导致这种情况发生,我该如何制止它?我正在使用Windows 8并具有IE10.
What is causing this to happen and how can I stop it? I am using Windows 8 and have IE10.
<html>
<head>
<HTA:APPLICATION
APPLICATIONNAME="Simple HTA"
SINGLEINSTANCE = "Yes"
SYSMENU="yes">
<title>Simple HTA</title>
<style type="text/css">
body {background-color:lightsteelblue;}
p {font:bold 18px arial;}
</style>
<script language="VBScript">
sub checkEnter
With document.parentWindow.event
if .keycode = 13 then
Validate()
End if
End With
End sub
sub validate()
x=msgbox("success")
End sub
</script>
</head>
<body>
<form>
<input type="text" onkeydown=checkEnter size=60 id="request" value="" />
<input type="button" name="btnStart" value="Start" onClick="Validate()" />
</form>
</body>
</html>
推荐答案
之所以会发生这种情况,是因为在文本输入中按 ENTER 时,"HTA内的一个IE会提交"表单.有两种方法可以解决此问题:
This happens, because "a little IE inside HTA" submits the form when pressing ENTER on a text input. There's a couple of ways to fix this:
如果不需要form
,只需将其删除,或将其替换为div
.
If you don't need the form
, just remove it, or replace it with a div
.
将功能用作checkEnter
并设置:
event.cancelBubble = true
event.returnValue = false
return false
这篇关于HTA在enterbutton上打开Internet Explorer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!