[英]Enable input field after checkbox is checked in list of checkboxes
我有一個從數據庫獲取數據的列表,我想啟用已選中復選框的輸入字段。 但是,它僅適用於第一行。 這是HTML代碼:
<?php
require_once('inc/config.php');
include 'verification/verify_form_details.php';
?>
<html>
<head>
<title>getElementById example</title>
<script type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
</head>
<body>
<?php
$result2 = getProcessID();
?>
<label>Process: <small style="color:red;">*</small>
<?php
while ($row = mysql_fetch_array($result2))
{
$row[0] = cleanOutputData($row[0]);
?>
<div>
<label>
<input type="checkbox" class="checkbox" name="process[]" id=<?php echo $row[0] ?> value=<?php echo $row[0]?> /><?php echo $row[0] ?>
</label>
<label>
<input type="text" class="field" disabled name="number[]" id=<?php echo $row[0] ?> />
</label>
</div>
<?php
}
mysql_free_result($result2);
?>
</label>
</body>
</html>
和javascript函數:
<script>
$(document).ready(function () {
$('.checkbox').change(function() {
$('.field').attr('disabled',!this.checked)
});
});
</script>
任何想法我怎么做? 謝謝
$('.checkbox').change(function() { $(this).parent().next().find('.field').prop('disabled', !$(this).is(':checked')) });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <label> <input type="checkbox" class="checkbox" name="process[]" id=v alue=/> </label> <label> <input type="text" class="field" disabled name="number[]" id=/> </label> <label> <input type="checkbox" class="checkbox" name="process[]" id=v alue=/> </label> <label> <input type="text" class="field" disabled name="number[]" id=/> </label> <label> <input type="checkbox" class="checkbox" name="process[]" id=v alue=/> </label> <label> <input type="text" class="field" disabled name="number[]" id=/> </label>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.