输入最大值等于 javascript 变量 [英] Input max equal to javascript variable

查看:39
本文介绍了输入最大值等于 javascript 变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使数字输入字段的最大值等于 javascript 变量?这个变量会改变,最大值也需要随之改变.

How do you make the maximum value of a number input field equal to a javascript variable? This variable will change, and the max needs to change with it.

您无法像使用 php 那样定义它,而且我对 javascript 不是很熟悉,我的搜索没有任何结果.

You can't define it the way you can with php, and I'm not very familiar with javascript and my searches have brought up nothing.

示例小提琴:http://jsfiddle.net/KDJdZ/

推荐答案

首先为您的输入分配 ID:

First assign ID to your input:

<input id="myInput" type="number" min="1" max="*jsvariable*"/>

然后通过javascript访问它:

Then access it via javascript:

var input = document.getElementById("myInput");
input.setAttribute("max",100); // set a new value;

或者使用你的变量

input.setAttribute("max",your_variable); // set a new value;

这篇关于输入最大值等于 javascript 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆