JavaScript变量到滑块max属性

时间:2014-05-23 11:27:32

标签: javascript html variables max

有没有办法将JavaScript变量放入滑块的" max" 属性值? 例如,

<script type="text/javascript">
myVar="20";
</script>


<input id="slider1" name="sliderr" type="range" max="myVar"></input>

2 个答案:

答案 0 :(得分:3)

试试这个

var myVar = 20;
document.getElementById("slider1").max = myVar;
// or
//document.getElementById("slider1").setAttribute("max", myVar);

Demo

答案 1 :(得分:2)

试试这个:

<强> HTML

<input id="slider1" name="sliderr" type="range" max="myVar"></input>

<强> JS

document.getElementById("slider1").setAttribute("max",20);

fiddle