[英]OnClick function is not working in IE 10, but fine in older versions
Within a standard Dot.Net application there is an option to add buttons, which can do certain functions. 在标准的Dot.Net应用程序中,有一个添加按钮的选项,该按钮可以执行某些功能。
This button, when clicked, opens Google in a new window with an input parameter from the current window. 单击此按钮后,将在新窗口中打开Google,其中包含当前窗口中的输入参数。
<button class="exButton" language="VBS" onclick="MakeReq()">Search Google</button>
<script language="VBS">
Sub MakeReq()
window.open "https://www.google.nl/?gws_rd=ssl#q=" & frmMain.FreeTextField_01.Value
End Sub
</script>
The button works fine in IE9 or in IE10 in compatibility mode. 在兼容模式下,该按钮在IE9或IE10中可以正常工作。 However on Chrome or IE 10 it does not function.
但是,在Chrome或IE 10上它不起作用。 I get no response or visible error.
我没有响应或可见错误。
Does anyone know: 有人知道吗:
Please keep in mind I can only influence this small piece of script as the rest of the page is controlled by the supplier of the application. 请记住,由于页面的其余部分由应用程序的供应商控制,因此我只能影响这一小段脚本。
Move to javascript, something like this: 转到javascript,如下所示:
<button class="exButton" onclick="MakeReq()">Search Google</button>
<script language="text/javascript">
function MakeReq() {
frmMain = document.forms[0]; // if it is the first form
textField = frmMain.elements["FreeTextField_01"];
window.open("https://www.google.nl/?gws_rd=ssl#q="+textField.value;
}
</script>
But it's not cleat what is frmMain.FreeTextField_01.value, so I tried to imagine it is a field in the first form in the page. 但这不是什么是frmMain.FreeTextField_01.value,因此我试图想象它是页面中第一种形式的字段。
Other ways could be: 其他方式可能是:
textField = document.getElementsByName("FreeTextField_01")[0];
or 要么
frmMain = document.forms["frmMain"];
textField = frmMain.elements["FreeTextField_01"];
or 要么
frmMain = document.forms[0]; // if it is the first form
textField = frmMain.elements[0]; // if it is the first form element
or 要么
frmMain = document.getElementById("frmMain");
textField = frmMain.elements["FreeTextField_01"];
if the form has an id="frmMain" 如果表单具有id =“ frmMain”
Thanks for the help! 谢谢您的帮助! Below is what ended up working for me.
以下是最终为我工作的内容。
<button class="exButton" onclick="myFunction()">Google Search</button>
<script language="text/javascript">
function myFunction()
{
frmMain = document.getElementById("frmMain");
textField = frmMain.elements["FreeTextField_01"];
window.open("google.nl/?gws_rd=ssl#q="+textField.value);
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.