【问题标题】:Make a button alternate colours when clicked in HTA?在 HTA 中单击时使按钮交替颜色?
【发布时间】:2018-07-09 23:19:59
【问题描述】:

我正在制作一个包含按钮的 HTA 应用程序,我希望按钮在单击时交替显示颜色(例如橙色/绿色),我找到了一个与 .html 扩展名一起使用的脚本,但在出现脚本错误时使用 .hta 扩展名运行。请告诉如何修复。 (是的,我需要坚持使用 hta)

注意,这是HTML Application,如果下面的代码在标准浏览器中运行,它就可以正常工作

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>

编辑:错误图像,https://imgur.com/a/ex0mw9P

【问题讨论】:

标签: javascript html css button hta


【解决方案1】:

您的 HTA 不会运行该版本的 jQuery 的主要原因是因为 HTA 默认以兼容模式运行,如 Internet Explorer 7,并且不支持像 addEventListeners 这样的方法。

如果您将此警报添加到您的 my.js 代码中,您将看到打印了哪些用户代理。

alert(window.navigator.userAgent);

所以要让它工作,你需要使用 IE7 兼容的方法,或者改变渲染引擎。

要更改引擎,请将此元标记添加到您的 &lt;head&gt;

<meta http-equiv="x-ua-compatible" content="ie=edge" />

【讨论】:

  • @user473470 尝试添加此元&lt;meta http-equiv="x-ua-compatible" content="ie=edge" /&gt; 并告诉我。如果够了,我会更新我的答案
  • 谢谢!我只需要添加
【解决方案2】:

为什么不这样做:删除开头的 jQuery 部分并替换为

$(document).ready(function(){
    $('.select').click(function() {
        $(this).toggleClass('highlight')
    })
})

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2012-12-06
  • 1970-01-01
  • 2020-04-05
  • 2021-07-07
  • 1970-01-01
  • 1970-01-01
  • 2012-08-02
  • 2023-04-05
相关资源
最近更新 更多