如何获取所选的选择是单击

时间:2017-09-24 04:21:17

标签: php ajax

我有多个下拉框,它是循环的结果。

for (n = 0; norm < 4.0 && n < N; ++n) 
  {
    __asm {
        // Create (old_x * old_x * old_x)
        fld x;
        fmul x;
        fmul x;

        // Create (3 * old_y * old_y * old_x)
        fld three;
        fmul y;
        fmul y;
        fmul x;

        // Create the full equation for x
        fsubp st(1), st(0);
        fadd cRe;

        // Create (3 * old_y * old_x * old_x) + cIm
        fld three;
        fmul y;
        fmul x;
        fmul x;
        fadd cIm;

        // Create (old_y * old_y * old_y)
        fld y;
        fmul y;
        fmul y;

        fsubp st(1), st(0); // Create the full equation for y

        fst y;              // Store in y to use for next loop
        fmul st(0), st(0);  // Get y*y

        fxch st(1);         // Swap places of y*y with newly calculated x
        fst x;              // Store in x to use for next loop

        fmul st(0), st(0);  // Get x*x

        faddp st(1), st(0); // Get x*x + y*y
        fst norm;           // Set loop variable
    }
  }

每当我想点击一个选择框时,它会从php填充数据并在点击的框中显示为选项。

这是我的ajax

foreach($Transs as $Trans){
<select data-id="'.$Trans->coursetitle.'" name = "Schedule" id = "Schedule" class = "form-control" '.$disabled.'>
<option></option>
</select>
}

但是会发生的事情是只填充第一个下拉框而不是我点击的内容。

1 个答案:

答案 0 :(得分:0)

HTML页面必须包含唯一ID。您为多个选择提供相同的ID,这就是为什么只有第一个id事件完成。将您的ID更改为类然后执行操作

foreach($Transs as $Trans){
echo '<select data-id="'.$Trans->coursetitle.'" name = "Schedule" class = "form-control Schedule" '.$disabled.'>
<option></option>
</select>';
}

的Ajax:

<script>

$(document).on("click", ".Schedule", function () {
    var subid = $(this).data('id');
    var dataString = 'id=' + subid;
    var attr = $(this);
    $.ajax({
        type: "POST",
        url: "../class/formschedule.class.php",
        data: dataString,
        cache: false,
        dataType: 'json',
        success: function (data) {
            var len = data.length;
            $(attr).empty();
            for( var i = 0; i<len; i++){
                var id = data[i]['id'];
                var name = data[i]['name'];

                $(attr).append("<option value='"+id+"'>"+name+"</option>");

            }
        }
    });
});
</script>