html - JavaScript variable to slider max attribute - Stack Overflow

Is there a way to put a JavaScript variable into slider's "max" attribute value?For exa

Is there a way to put a JavaScript variable into slider's "max" attribute value? For example,

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


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

Is there a way to put a JavaScript variable into slider's "max" attribute value? For example,

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


<input id="slider1" name="sliderr" type="range" max="myVar"></input>
Share Improve this question asked May 23, 2014 at 11:27 StartedFromTheBottomStartedFromTheBottom 3258 silver badges21 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

Try this

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

Demo

Try this:

html

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

js

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

fiddle

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744996378a4605216.html

相关推荐

  • html - JavaScript variable to slider max attribute - Stack Overflow

    Is there a way to put a JavaScript variable into slider's "max" attribute value?For exa

    18小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信