[我仅填写的已启用字段] [1]
我的表格如下图所示。 我要禁用的所有字段,但我填写的字段除外,当我转到下一个字段时,我填写的上一个字段将被禁用。 我已经搜索过,但无法弄清楚 https://i.stack.imgur.com/0ATvQ.png
答案 0 :(得分:0)
您可以将只读形式的所有字段设置为只读,并且仅启用通过以下代码在其中输入的一个输入:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Vertical (basic) form</h2>
<form action="/action_page.php" method="post" name="subForm" id="subForm">
<div class="form-group">
<label for="email">Email:</label>
<input type="email" class="form-control" id="email" placeholder="Enter email" name="email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="password" placeholder="Enter password" name="password">
</div>
<div class="form-group">
<label for="pwd">Number:</label>
<input type="number" class="form-control" id="number" placeholder="Enter Number" name="number">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
<script type="text/javascript">
function disableinputs(){
$("#subForm input").prop('readonly', true);
}
$(document).ready(function(){
disableinputs();
});
$(document).on('click','#subForm input',function(){
$(this).prop('readonly', false);
});
$(document).on('focus','#subForm input',function(){
$(this).prop('readonly', false);
});
$(document).on('focusout','#subForm input',function(){
disableinputs();
});
</script>
</body>
</html>