I am making a HTA application that will have buttons in it, I wanted the buttons to alternate colours when clicked (eg. orange/green), I found a script that worked with the .html extension but has a script error when run with the .hta extension. Please tell how to fix. (Yes, I need to stick with hta)
我正在制作一个HTA应用程序,其中包含按钮,我希望按钮在单击时交替显示颜色(例如橙色/绿色),我发现一个脚本与.html扩展名一起工作,但在运行时出现脚本错误.hta扩展名。请告诉我们如何解决。 (是的,我需要坚持使用hta)
Note, this is a HTML Application, and if the below code runs in a standard browser it will work just fine
请注意,这是一个HTML应用程序,如果以下代码在标准浏览器中运行,它将正常工作
JS
jQuery(function($) {
$('.select').click(function() {
$(this).toggleClass('highlight')
})
})
CSS
.select {
background: rgb(255, 145, 0);
}
.select.highlight {
background: rgb(26, 255, 0);
}
HTML
<body>
<input type="button" name="Ignore Select" value="Ignore Select" id="select" class="select" />
<input type="button" name="Ignore Delete" value="Ignore Delete" id="select1" class="select" />
<input type="button" name="Ignore Insert" value="Ignore Insert" id="select2" class="select" />
<input type="button" name="Ignore Update" value="Ignore Update" id="select3" class="select" />
<input type="button" name="Ignore Sleep" value="Ignore Sleep" id="select4" class="select" />
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="my.js"></script>
EDIT: Images of the error, https://imgur.com/a/ex0mw9P
编辑:错误的图像,https://imgur.com/a/ex0mw9P
2 个解决方案
#1
1
The main reason your HTA won't run that version of jQuery is because HTA by default runs in compatibility mode, as Internet Explorer 7, and doesn't support methods like addEventListeners
.
你的HTA不会运行那个版本的jQuery的主要原因是因为HTA默认以兼容模式运行,如Internet Explorer 7,并且不支持addEventListeners等方法。
If you add this alert to your my.js
code you'll see which user agents gets printed.
如果将此警报添加到my.js代码中,您将看到打印了哪些用户代理。
alert(window.navigator.userAgent);
So to make it work you need to use IE7 compatible methods, or change the render engine.
因此,要使其工作,您需要使用IE7兼容的方法,或更改渲染引擎。
To change engine, add this meta tag in your <head>
要更改引擎,请在中添加此元标记
<meta http-equiv="x-ua-compatible" content="ie=edge" />
#2
0
why not just do this: remove the jQuery part in the beggining and replace it with
为什么不这样做:删除beggining中的jQuery部分并替换它
$(document).ready(function(){
$('.select').click(function() {
$(this).toggleClass('highlight')
})
})
#1
1
The main reason your HTA won't run that version of jQuery is because HTA by default runs in compatibility mode, as Internet Explorer 7, and doesn't support methods like addEventListeners
.
你的HTA不会运行那个版本的jQuery的主要原因是因为HTA默认以兼容模式运行,如Internet Explorer 7,并且不支持addEventListeners等方法。
If you add this alert to your my.js
code you'll see which user agents gets printed.
如果将此警报添加到my.js代码中,您将看到打印了哪些用户代理。
alert(window.navigator.userAgent);
So to make it work you need to use IE7 compatible methods, or change the render engine.
因此,要使其工作,您需要使用IE7兼容的方法,或更改渲染引擎。
To change engine, add this meta tag in your <head>
要更改引擎,请在中添加此元标记
<meta http-equiv="x-ua-compatible" content="ie=edge" />
#2
0
why not just do this: remove the jQuery part in the beggining and replace it with
为什么不这样做:删除beggining中的jQuery部分并替换它
$(document).ready(function(){
$('.select').click(function() {
$(this).toggleClass('highlight')
})
})