下面的代码笔链接显示了一个简单的范围滑块,我想在我的.hta文件中工作。
Codepen Link
问题是,当前运行.hta文件时,我得到“$is undefined error”,然后单击“Yes”继续时,它只显示:
我想可能是因为jQuery库没有加载,所以我补充道:
<script src="//code.jquery.com/jquery-1.9.1.min.js"></script>
但这只会延迟hta大约30秒,然后显示相同的错误。
下面是范围滑块的脚本:
var range = $('.input-range'),
value = $('.range-value');
value.html(range.attr('value'));
range.on('input', function(){
value.html(this.value);
});
这是我的HTA代码。非常感谢您的帮助:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<meta charset="UTF-8">
<title>Adjustments</title>
<script type="text/vbscript" language="vbscript">
Sub window_onload()
window.resizeTo 338,545
End Sub
</SCRIPT>
<script src="//code.jquery.com/jquery-1.9.1.min.js"></script>
<HTA:APPLICATION icon="C:\Users\ME\Desktop\Abacus\compIcon.ico"
APPLICATIONNAME="WELCOME"
SCROLL="no"
SINGLEINSTANCE="no"
WINDOWSTATE="normal"
MinimizeButton="yes"
MaximizeButton="no"
RESIZE="no"
CAPTION="no"
>
<script type='text/javascript'>
$(document).ready(function() {
var range = $('.input-range'),
value = $('.range-value');
value.html(range.attr('value'));
range.on('input', function(){
value.html(this.value);
});
});
</script>
<style>
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
font-family: sans-serif;
padding: 40px;
}
.range-slider {
// Slider
.input-range {
-webkit-appearance: none;
width: 300px;
height: 10px;
border-radius: 5px;
background: #ccc;
outline: none;
// Slider Handle
&::-webkit-slider-thumb {
-webkit-appearance: none;
width: 20px;
height: 20px;
border-radius: 50%;
background: #353535;
cursor: pointer;
-webkit-transition: background .15s ease-in-out;
transition: background .15s ease-in-out;
&:hover {
background: #e06161;
}
}
&:active::-webkit-slider-thumb {
background: #e06161;
}
&::-moz-range-thumb {
width:20px;
height: 20px;
border: 0;
border-radius: 50%;
background: #353535;
cursor: pointer;
-webkit-transition: background .15s ease-in-out;
transition: background .15s ease-in-out;
&:hover {
background: #e06161;
}
}
&:active::-moz-range-thumb {
background: #e06161;
}
}
// Tooltip Tag
.range-value {
display: inline-block;
position: relative;
width: 80px;
color: #fff;
font-size: 16px;
line-height: 20px;
text-align: center;
border-radius: 3px;
background: #353535;
padding: 5px 10px;
margin-left: 7px;
&:after {
position: absolute;
top: 8px;
left: -7px;
width: 0;
height: 0;
border-top: 7px solid transparent;
border-right: 7px solid #353535;
border-bottom: 7px solid transparent;
content: '';
}
}
}
// Firefox Overrides
::-moz-range-track {
background: #ccc;
border: 0;
}
input::-moz-focus-inner {
border: 0;
}
</style>
</head>
<body>
<div class="range-slider">
<input class="input-range" type="range" value="0" min="-75000" step="500" max="75000">
<span class="range-value"></span>
</div>
</body>
</html>
最佳答案
//code.jquery.com/jquery-1.9.1.min.js
是与协议相关的URL。然而,HTA既不是HTTP也不是HTTPs资源。观察网络请求(使用Fiddler等工具)将显示jQuery脚本无法下载。
改用http://code.jquery.com/jquery-1.9.1.min.js
作为jQuery源。
关于javascript - 尝试将范围滑动条添加到.hta文件时出现错误“$ is undefined”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31778339/