javascript - 为什么我的页面上没有出现 JQuery UI 滑块?
问题描述
我试图让 JQuery UI 在我的 HTML 页面上工作但没有成功。具体来说,我想使用范围滑块,但无法在页面上显示任何内容。我已经下载了 JQuery UI 文件夹并将其导入到我的代码文件中。我现在拥有的代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="/styles.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.css" />
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="/jquery-ui-1.12.1.custom/jquery-ui.min.css">
<script src="/jquery-ui-1.12.1.custom/external/jquery/jquery.js"></script>
<script src="/jquery-ui-1.12.1.custom/jquery-ui.min.js"></script>
<script>
$( function() {
$( "#slider-range" ).slider({
range: true,
min: 0,
max: 500,
values: [ 75, 300 ],
slide: function( event, ui ) {
$( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
}
});
$( "#amount" ).val( "$" + $( "#slider-range" ).slider( "values", 0 ) +
" - $" + $( "#slider-range" ).slider( "values", 1 ) );
} );
</script>
</head>
<body>
<section class = "nav-bar"></section>
<p>
<label for="amount">Price range:</label>
<input type="text" id="amount" readonly style="border:0; color:#f6931f; font-weight:bold;">
</p>
<div id="slider-range"></div>
</section>
非常感谢任何人对此的帮助!
解决方案
自定义的 jQuery 脚本会导致问题。我评论了你的并添加了默认的 js 和缺少的 css。(最好将脚本移动到页脚)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="/styles.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.css" />
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap" rel="stylesheet">
<!-- my Styles start -->
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<!-- my Styles end -->
<link rel="stylesheet" href="/jquery-ui-1.12.1.custom/jquery-ui.min.css">
<!-- my jQuery start -->
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<!-- my jQuery end -->
<!-- my Script start -->
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<!-- my Script end -->
<!-- <script src="/jquery-ui-1.12.1.custom/external/jquery/jquery.js"></script> -->
<!-- <script src="/jquery-ui-1.12.1.custom/jquery-ui.min.js"></script> -->
<script>
$( function() {
$( "#slider-range" ).slider({
range: true,
min: 0,
max: 500,
values: [ 75, 300 ],
slide: function( event, ui ) {
$( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
}
});
$( "#amount" ).val( "$" + $( "#slider-range" ).slider( "values", 0 ) +
" - $" + $( "#slider-range" ).slider( "values", 1 ) );
} );
</script>
</head>
<body>
<section class = "nav-bar"></section>
<p>
<label for="amount">Price range:</label>
<input type="text" id="amount" readonly style="border:0; color:#f6931f; font-weight:bold;">
</p>
<div id="slider-range"></div>
</body>
推荐阅读
- dart - 是否可以在 Dart 类上要求泛型类型参数?
- android - 在 Android Studio 中开发的 Flutter 项目的合法 .gitignore 是什么?
- python - Python Pandas 按一列分组
- firebase - 我应该如何在不破坏嵌套的情况下过滤 RECORD 中的列?
- sql - 确定连续和独立的 PTO 天数
- powershell - 在 Powershell 中高效处理多个 CSV
- java - android - 如果未进行搜索,则隐藏 recyclerview
- java - 使用 Spring WebClient + ConfigServer
- javascript - 我的函数说 Uncaught TypeError: $(...).reverse is not a function
- swift - Swift - 如果用户输入 1 到 100,则显示随机消息