我在更改时遇到问题 max
在<input type='number'>
。这是我的示例代码:
$(document).ready(function(){
var total = 5;
$(.foo).attr('max', total);
$(.bar).attr('max', total);
$(.ext).attr('max', total);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<input type='number' name='foo' class='foo'>
<br>
<input type='number' name='bar' class='bar'>
<br>
<input type='number' name='ext' class='ext'>
</body>
如何制作max
一定不>总计?
示例:如果我在 foo 上输入 2,在 bar 上输入 1,则 ext 不得大于 2。
谢谢
最佳答案
正如 Chris 在评论中提到的,它应该是 '.foo'
而不是 .foo
。另外,作为一种速记方式,您可以将它们放在一个语句中,如下所示,如果全部具有相同的 max
,则 $('.foo, .bar, .ext')
。
$(document).ready(function(){
var total = 5;
$('.foo, .bar, .ext').attr('max', total);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<form action="http://stackoverflow.com">
<input type='number' name='foo' class='foo'>
<br>
<input type='number' name='bar' class='bar'>
<br>
<input type='number' name='ext' class='ext'>
<br>
<input type='submit' value='Submit' >
</form>
</body>
关于javascript - 使用jquery在html5中动态更改 `max`或 `min`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41030570/