jQuery UI Slider: Set Initial Data-Value for Handles
To initialize the data-value attribute for the .ui-slider-handle elements, you can modify the code as follows:
\
$(function() {\
$( "#slider-range" ).slider({\
range: true,\
min: 0,\
max: 2000,\
values: [ 0, 2000 ],\
slide: function( event, ui ) {\
$( "#amount" ).html( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );\
$( "#min" ).val(ui.values[ 0 ]);\
$( "#max" ).val(ui.values[ 1 ]);\
$(ui.handle).attr("data-value", ui.value); // Update handle popup value\
}\
});\
\
$( "#amount" ).html( "$" + $( "#slider-range" ).slider( "values", 0 ) +\
" - $" + $( "#slider-range" ).slider( "values", 1 ) );\
\
// Initialize handle popups with default values\
$("#slider-range .ui-slider-handle").each(function() {\
$(this).attr("data-value", $(this).slider("value"));\
});\
});\
```\
\
This will set the initial `data-value` attribute for each `.ui-slider-handle` element to its default value.
原文地址: https://www.cveoy.top/t/topic/qfhV 著作权归作者所有。请勿转载和采集!