【发布时间】:2019-12-19 05:50:21
【问题描述】:
我正在尝试克隆和初始化 jQuery 范围滑块,但它不起作用。
<table id="repeatable-fieldset-one" width="100%">
<thead>
<tr>
<th width="2%"></th>
<th width="30%">Name</th>
<th width="60%">Percentage</th>
<th width="2%"></th>
</tr>
</thead>
<tbody>
<tr>
<td><a class="button remove-row" href="#">-</a></td>
<td><input type="text" class="widefat" name="name[]" /></td>
<td><input type="range" min="10" max="100" value="20" name="progress_value[]" data-rangeSlider> <output></output></td>
<tr class="empty-row screen-reader-text">
<td><a class="button remove-row" href="#">-</a></td>
<td><input type="text" class="widefat" name="name[]" /></td>
<td><input type="range" min="10" max="100" value="30" name="progress_value[]" data-rangeSlider> <output></output></td>
</tr>
</tbody>
</table>
<p><a id="add-row" class="button" href="#">Add another</a>
<script type="text/javascript">
jQuery(document).ready(function($) {
var $document = $(document);
var selector = '[data-rangeslider]';
var $element = $(selector);
// For ie8 support
var textContent = ('textContent' in document) ? 'textContent' : 'innerText';
// Example functionality to demonstrate a value feedback
function valueOutput(element) {
var value = element.value;
var output = element.parentNode.getElementsByTagName('output')[0] || element.parentNode.parentNode.getElementsByTagName('output')[0];
output[textContent] = value;
}
$document.on('input', 'input[type="range"], ' + selector, function(e) {
valueOutput(e.target);
});
// Basic rangeslider initialization
$element.rangeslider({
// Deactivate the feature detection
polyfill: false,
// Callback function
onInit: function() {
valueOutput(this.$element[0]);
},
// Callback function
onSlide: function(position, value) {
console.log('onSlide');
console.log('position: ' + position, 'value: ' + value);
},
// Callback function
onSlideEnd: function(position, value) {
console.log('onSlideEnd');
console.log('position: ' + position, 'value: ' + value);
}
});
jQuery('#add-row').on('click', function() {
var row = $('.empty-row.screen-reader-text').clone(true);
row.removeClass('empty-row screen-reader-text');
row.insertBefore('#repeatable-fieldset-one tbody>tr:last');
return false;
});
jQuery('.remove-row').on('click', function() {
jQuery(this).parents('tr').remove();
return false;
});
jQuery('#repeatable-fieldset-one tbody').sortable({
opacity: 0.6,
revert: true,
cursor: 'move',
handle: '.sort'
});
//$('input[type="range"]').rangeslider();
// Basic rangeSlider initialization
jQuery('input[type="range"]').rangeslider({
polyfill : false,
onInit : function() {
this.output = $( '<div class="range-output" />' ).insertAfter( this.$range ).html( this.$element.val() );
},
onSlide : function( position, value ) {
this.output.html( value );
}
});
});
</script>
我已经在 codepen 上设置了一个演示。 https://codepen.io/rigalpatel/pen/GRgrLZR
当我克隆范围滑块时,它会用值克隆但它的禁用(不能更改克隆范围滑块的进度)。
有人帮忙解决这个问题吗?
谢谢
【问题讨论】:
-
它适用于您提供的 codepen。它改变了克隆滑块的进度。
-
到底是什么问题?看起来它正在 codepen 中工作。
-
当我添加 .empty-row { display:none; 时它不起作用我已经创建了空范围滑块来克隆它,但是当我添加空创建的兰德滑块 css 显示 none 然后它不起作用。
标签: javascript jquery rangeslider