【发布时间】:2018-07-27 09:35:16
【问题描述】:
[仅我填写的启用字段][1]
我有一个如下图所示的表格。 我希望除了我填写的字段之外的所有字段禁用,当我转到下一个字段时,我之前填写的字段将被禁用。 我已经搜索但无法弄清楚 https://i.stack.imgur.com/0ATvQ.png
【问题讨论】:
标签: jquery disabled-input
[仅我填写的启用字段][1]
我有一个如下图所示的表格。 我希望除了我填写的字段之外的所有字段禁用,当我转到下一个字段时,我之前填写的字段将被禁用。 我已经搜索但无法弄清楚 https://i.stack.imgur.com/0ATvQ.png
【问题讨论】:
标签: jquery disabled-input
您可以只读表单的所有字段,并且只启用您通过以下代码输入的一个输入:
<!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>
【讨论】: