如何设置<输入>的最大值和最小值在HTML5通过JavaScript或jQuery [英] how to set the max value and min value of <input> in html5 by javascript or jquery
问题描述
我试图找出如何通过javascript或jquery设置html5类型输入的最大值和最小值。
< input type =numbermax =??? MIN = ???步骤= 0.5/>
有人请指导
jQuery可以轻松设置元素的任何属性 - 只需使用 .attr ()
方法:
$(document).ready(function(){
$(输入)。attr({
max:10,//替换你自己的
min:2 //值(或变量)这里
});
});
如果脚本块出现在您想要的元素之后,则不需要文档就绪处理程序操作。
使用input
的选择器将设置 all 的属性虽然输入,所以真的你应该有一些方法来确定有问题的输入。如果你给它一个id,你可以说:
$(#idHere)。attr(...
...或带班级:
<$ p $ ($ .c $ c> $(。classHere)。attr(...
I am trying to find out how to set the max value and min value of html5 type input by javascript or jquery.
<input type="number" max="???" min="???" step="0.5"/>
Would someone please guide
jQuery makes it easy to set any attributes for an element - just use the .attr()
method:
$(document).ready(function() {
$("input").attr({
"max" : 10, // substitute your own
"min" : 2 // values (or variables) here
});
});
The document ready handler is not required if your script block appears after the element(s) you want to manipulate.
Using a selector of "input"
will set the attributes for all inputs though, so really you should have some way to identify the input in question. If you gave it an id you could say:
$("#idHere").attr(...
...or with a class:
$(".classHere").attr(...
这篇关于如何设置<输入>的最大值和最小值在HTML5通过JavaScript或jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!