Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery ui 无法从jQuery UI滑块范围获取索引_Jquery Ui_Slider - Fatal编程技术网

Jquery ui 无法从jQuery UI滑块范围获取索引

Jquery ui 无法从jQuery UI滑块范围获取索引,jquery-ui,slider,Jquery Ui,Slider,我花了很长时间试图从多个滑块的集合中获得(我认为是)一个简单的索引。HTML格式如下: <div id="left-values" class="line"> <span id="l1" style="padding: 0 1.8em;">0</span> <span id="l2" style="padding: 0 1.8em;">0</span> <span id="l3" style="paddin

我花了很长时间试图从多个滑块的集合中获得(我认为是)一个简单的索引。HTML格式如下:

<div id="left-values" class="line">
    <span id="l1" style="padding: 0 1.8em;">0</span>
    <span id="l2" style="padding: 0 1.8em;">0</span>
    <span id="l3" style="padding: 0 1.8em;">0</span>
    <span id="l4" style="padding: 0 1.8em;">0</span>
    <span id="l5" style="padding: 0 1.8em;">0</span>
    <span id="l6" style="padding: 0 1.8em;">0</span>
    <span id="l7" style="padding: 0 1.8em;">0</span>
    <span id="l8" style="padding: 0 1.8em;">0</span>
</div>

0
0
0
0
0
0
0
0
jQuery代码是:

    // setup audiometry sliders
    $("#eq > span").each(function (e) {
        // read initial values from markup and remove that
        var value = parseInt($(this).text());
        // var index = $(this).index; <- this didn't work.

        $(this).empty();
        $(this).slider({
            value: value,
            slide: function (event, ui) {
                //console.log($(this).attr('id')); <- neither did this.
                //console.log(index);
                $('#left-values span:first').text(ui.value);
            }
        })
    });
//设置测听滑块
$(“#eq>span”)。每个(函数(e){
//从标记中读取初始值并将其删除
var value=parseInt($(this.text());

//var index=$(this).index;您可以这样获得索引:

$("#eq > span").each(function (index, Element) {
    alert(index);
    ...

请参见您的工作原理,也许您还有其他工作。下面是一个独立的示例,请查看控制台的输出:

$(“#eq>span”)。每个(函数(e){
var value=parseInt($(this.text());
$(this.empty();
$(此).slider({
价值:价值,
最小:-10,
最高:10,
幻灯片:功能(事件、用户界面){

console.log($(this.attr('id'));//难以置信。我花了太多时间在jQuery UI的东西上闲逛,我完全忘记了调用函数。有人想因为我未能使用RTFM而否决我吗?谢谢你的指针。
$("#eq > span").each(function (e) {
    var value = parseInt($(this).text());    
    $(this).empty();
    $(this).slider({
        value: value,
        min: -10,
        max: 10,
        slide: function (event, ui) {
          console.log($(this).attr('id')); //<- works here, outputs l1, l2, etc
          console.log($(this).index()); //outputs 0, 1 .... 7 (0-based index)
        }
    });
});​