【发布时间】:2016-09-06 02:41:03
【问题描述】:
我有一个从数据库获取的数据列表,我想在选中的复选框上启用输入字段。然而,它只适用于第一行。这是 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>
任何想法我该怎么做?谢谢
【问题讨论】:
-
因为相同的
ID使用类代替。 ID 应该是唯一的 -
@guradio 我试过上课,现在按下一个复选框后,它启用了所有字段。还编辑了我的问题
-
使用
$(this).parent().next().find('.field').attr('disabled',!this.checked) -
@guradio 现在所有字段都处于禁用状态,即使选中了复选框
-
请看下面的答案
标签: javascript php jquery checkbox