【发布时间】:2021-07-29 16:04:23
【问题描述】:
我正在使用jquery-ui。 2 周后我无法解决此问题。
我不知道为什么点击滑块后出现此错误:
控制台 Firefox:
TypeError: o.element is undefined[Learn More] jquery-ui.min.js:6:6058
控制台镀铬:
jquery-ui.min.js:6 Uncaught TypeError: Cannot read property 'toggleClass' of undefined
at t.(anonymous function).(anonymous function)._toggleClass (http://localhost:8000/assets/frontend/_js/jquery-ui.min.js:6:6067)
at t.(anonymous function).(anonymous function)._addClass (http://localhost:8000/assets/frontend/_js/jquery-ui.min.js:6:5877)
at t.(anonymous function).(anonymous function)._mouseCapture (http://localhost:8000/assets/frontend/_js/jquery-ui.min.js:6:14171)
at t.(anonymous function).(anonymous function)._mouseCapture (http://localhost:8000/assets/frontend/_js/jquery-ui.min.js:6:1111)
at t.(anonymous function).(anonymous function)._mouseDown (http://localhost:8000/assets/frontend/_js/jquery-ui.min.js:6:9414)
at t.(anonymous function).(anonymous function)._mouseDown (http://localhost:8000/assets/frontend/_js/jquery-ui.min.js:6:1111)
at HTMLDivElement.<anonymous> (http://localhost:8000/assets/frontend/_js/jquery-ui.min.js:6:8701)
at HTMLDivElement.dispatch (http://localhost:8000/assets/frontend/_js/jquery-3.1.1.min.js:3:10315)
at HTMLDivElement.q.handle (http://localhost:8000/assets/frontend/_js/jquery-3.1.1.min.js:3:8342)
<script type="text/javascript" src="http://localhost:8000/assets/frontend/_js/jquery-3.1.1.min.js"></script>
<!-- http://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js -->
<script type="text/javascript" src="http://localhost:8000/assets/frontend/_js/bootstrap.min.js"></script>
<!-- https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js -->
<script type="text/javascript" src="http://localhost:8000/assets/frontend/_js/jasny-bootstrap.min.js"></script>
<script type="text/javascript" src="http://localhost:8000/assets/frontend/_js/bootstrap-select.min.js"></script>
<script type="text/javascript" src="http://localhost:8000/assets/frontend/_js/persian-datepicker.min.js"></script>
<script type="text/javascript" src="http://localhost:8000/assets/frontend/_js/script.js"></script>
<script type="text/javascript" src="http://localhost:8000/assets/frontend/_js/jquery-ui.min.js"></script>
<script type="text/javascript" src="http://localhost:8000/assets/frontend/_js/jquery.ui.touch-punch.min.js"></script>
<script>
$(document).ready(function(){
$( "#slider" ).slider({
range: true,
min: -10000000,
max: -1000,
values: [ -8000000, -2000 ],
slide: function(event, ui) {
$(".amount .min-price").text(addCommas (ui.values[1]*-1) + " ریال ");
$(".amount .max-price").text(addCommas (ui.values[0]*-1) + " ریال ");
}
});
$(".amount .min-price").text(addCommas ($("#slider").slider( "values", 1 )*-1 ) + " ریال ");
$(".amount .max-price").text(addCommas ($("#slider").slider( "values", 0 )*-1 ) + " ریال ");
// Hover states on the static widgets
$( "#dialog-link, #icons li" ).hover(
function() {
$( this ).addClass( "ui-state-hover" );
},
function() {
$( this ).removeClass( "ui-state-hover" );
}
);
});
</script>
我的 HTML 代码:
<div class="col-md-12">
<div id="slider" class="ui-slider ui-corner-all ui-slider-horizontal ui-widget ui-widget-content">
<div class="ui-slider-range ui-corner-all ui-widget-header">
</div>
<span tabindex="1" class="ui-slider-handle ui-corner-all ui-state-default">
</span>
<span tabindex="2" class="ui-slider-handle ui-corner-all ui-state-default" >
</span>
</div>
</div>
//used in slider
function addCommas(nStr){
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
我的网站地址:
http://tahrircenter.com/products
我删除了额外的代码,但我得到了同样的错误:
在jsfiddle 上运行良好!!!:
https://jsfiddle.net/Twisty/3gm3sfem/
.toggleClass() 是 jQuery 的一个函数,所以如果你遇到错误 它是未定义的,那么有可能另一个版本的 jQuery 可能 被加载到别处。或者根本没有加载。
【问题讨论】:
标签: javascript jquery html jquery-ui