HTML输入范围内的功能 - 无法正常工作

时间:2014-11-08 01:04:40

标签: javascript jquery html5

我有javascript代码为表中的每个元素添加一行表。该行包含一个滑块输入和一个将显示滑块值的单元格。我的函数showVal用于更新包含滑块值的单元格。任何想法为什么这可能不起作用?谢谢!

var showVal = function(newVal){
   $('#sliderTable tbody tr:last-child td:last-child').html(newVal);
};

var sliderCreate = function(array1,array2){
   for (i=0; i<array1.length; i++){
     $('#sliderTable tbody').append('<tr><td>HI</td><td>Bye</td><td></td></tr>');
     $('#sliderTable tbody tr:last-child td:first-child').html(array1[i] + ': ');
     $('#sliderTable tbody tr:last-child td:nth-child(2)').html('<input type="range" oninput="showVal(this.value)" min="0" max="'+ initCheckVal +'">');
     $('#sliderTable tbody tr:last-child td:last-child').html(array2[i]);
   }
};

1 个答案:

答案 0 :(得分:0)

如果没有看到代码的完整上下文,很难说,但如果您根本没有看到滑块,则问题可能是initCheckVal未定义引起的。我没看到你在哪里定义它,所以我肯定会先检查它。

Javascript不喜欢字符串连接未定义的变量(它不能),所以如果initCheckVal在循环的第一次迭代中没有设置值,你就不会看到任何变量您尝试连接到TD的HTML。