如何用 jQuery 停用/啟用一個輸入框?
我們可以很容易地透過“停用”停用屬性來停用輸入框(文字框、文字域)。
$(‘elementname’).attr(‘disabled’,’disabled’);
要啟用停用的元素,我們需要從該元素中移除“停用”屬性。
$(‘elementname’).removeAttr(‘disabled’);
示例
<html >
<head>
<title>ed</title>
<script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#btn1').click(function () {
$('input').attr('disabled', 'disabled');
});
$('#btn2').click(function () {
$('input').removeAttr('disabled');
});
});
</script>
</head>
<body>
<div>
<input type="text" id="tt1" /><br />
<button type="button" id="btn1">Disable</button>
<button type="button" id="btn2">Enable</button>
</div>
</body>
</html>
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP