javascript – 更改另一个滑块时更新材质滑块UI

我的输入有问题.两个输入都已连接.当您单击第一个输入时,第二个输入将移动但css将不会更新.

var $ra1 = $('#range1');
var $ra2 = $('#range2');

$ra1.on('input', function() {
    $ra2.val(this.max - this.value);
});
$ra2.on('input', function() {
    $ra1.val(this.max - this.value);
});
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Range 1
<input type="range" min="0" max="400" value="0" class="mdl-slider mdl-js-slider " id="range1">

Range 2
<input type="range" min="0" max="400" value="400" class="mdl-slider mdl-js-slider" id="range2">

enter image description here

编辑:
我找到了IE11的解决方法

var $ra1 = $('#range1');
var $ra2 = $('#range2');
if (navigator.appName == 'Microsoft Internet Explorer' ||  !!(navigator.userAgent.match(/Trident/) || navigator.userAgent.match(/rv:11/)) || (typeof $.browser !== "undefined" && $.browser.msie == 1)){
    $ra1.change(function(){
        $ra2.get(0).MaterialSlider.change(this.max - this.value);
    });
    $ra2.change(function(){
        $ra1.get(0).MaterialSlider.change(this.max - this.value);
    });
 }else{
    $ra1.on('input', function() {
        $ra2.get(0).MaterialSlider.change(this.max - this.value);
    });
    $ra2.on('input', function() {
        $ra1.get(0).MaterialSlider.change(this.max - this.value);
    });
 }
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Range 1
<input type="range" min="0" max="400" value="0" class="mdl-slider mdl-js-slider " id="range1"> 
Range 2
<input type="range" min="0" max="400" value="400" class="mdl-slider mdl-js-slider" id="range2">

解决方法:

为此,您需要通过Material库而不是jQuery设置值,以便更新UI.为此,请在DOM元素的MaterialSlider属性上使用change函数,如下所示:

var $ra1 = $('#range1');
var $ra2 = $('#range2');

$ra1.on('input', function() {
  $ra2.get(0).MaterialSlider.change(this.max - this.value);
});

$ra2.on('input', function() {
  $ra1.get(0).MaterialSlider.change(this.max - this.value);
});
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Range 1
<input type="range" min="0" max="400" value="0" class="mdl-slider mdl-js-slider " id="range1"> Range 2
<input type="range" min="0" max="400" value="400" class="mdl-slider mdl-js-slider" id="range2">

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...