<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>shawl.qiu template</title>
<script type="text/javascript">
//<![CDATA[
</script>
</head>
<body>
名称<input type="text" name="cbx" id="ipt_1" onchange="fn()">
IP<input type="text" name="cbx" id="ipt_2" onchange="fn1()">
端口<input type="text" name="cbx" id="ipt_3" onchange="fn2()">
所属城市<input type="text" name="cbx" id="ipt_4" onchange="fn3()">
所属机房<input type="text" name="cbx" id="ipt_5">
</body>
</html>
<script src="https://code.jquery.com/jquery-3.3.1.min.js "></script>
<script>
var ipt_1 = $('#ipt_1');
var ipt_2 = $('#ipt_2');
var ipt_3 = $('#ipt_3');
var ipt_4 = $('#ipt_4');
var ipt_5 = $('#ipt_5');
if (ipt_1.val() == '') {
ipt_2.attr('readonly', 'readonly');
ipt_3.attr('readonly', 'readonly');
ipt_4.attr('readonly', 'readonly');
ipt_5.attr('readonly', 'readonly');
}
// 第一个判断
function fn() {
if (ipt_1.val() !== '') {
ipt_2.removeAttr('readonly');
ipt_3.removeAttr('readonly');
ipt_4.removeAttr('readonly');
ipt_5.removeAttr('readonly');
}
if (ipt_2.val() == '') {
ipt_3.attr('readonly', 'readonly');
ipt_4.attr('readonly', 'readonly');
ipt_5.attr('readonly', 'readonly');
}
}
// 判断第二
function fn1() {
if (ipt_2.val() !== '') {
ipt_3.removeAttr('readonly');
ipt_4.removeAttr('readonly');
ipt_5.removeAttr('readonly');
}
if (ipt_3.val() == '') {
ipt_4.attr('readonly', 'readonly');
ipt_5.attr('readonly', 'readonly');
}
}
// 判断第三个
function fn2() {
if (ipt_4.val() !== '') {
ipt_5.attr('readonly', 'readonly');
}
if (ipt_4.val() == '') {
ipt_4.removeAttr('readonly');
}
}
// 判断第四个
function fn3() {
if (ipt_4.val() !== '') {
ipt_5.removeAttr('readonly');
}
}
</script>
按顺序写input框
最新推荐文章于 2022-03-10 19:27:33 发布