*请帮助我,我只是一个初学者
我在这个foreach块上面有输入字段,但这是我关注的焦点。
foreach ($display_eqp as $value){
$eqpid = $value['Eqp_ID'];
$available = $value['OnHand'];
echo "<tr>";
echo "<td class='center'><input type='checkbox' class='checkbox'
name='request-equipment[". $eqpid ."]' id='". $eqpid ."-checkbox'
value=" . $eqpid . " onchange='enableQtyTxtbox(this.value)' disabled></td>";
echo "<td class='center'><input type='text' class='form-control'
style='width: 60px;' name='available-" . $eqpid . "' id='available-" . $eqpid . "'
value=" . $available . " readonly></td>";
echo "<td class='center'><input type='text' placeholder='...' class='form-control'
style='width: 60px;' onchange='checkQty(this.value, ". $eqpid .")'
name='request-quantity[". $eqpid ."]' id='". $eqpid ."' disabled='true'/></td>";
echo "</tr>";
我有2个javascripts。
第一个就是这个,当一个单独的复选框选中状态改变时,它启用/禁用并清除相应的文本框并启用/禁用提交按钮。这是有效的,仅适用于个人,这可以通过勾选复选框来触发。
function enableQtyTxtbox(val) {
var checkbox = document.getElementById(val + "-checkbox");
var textbox = document.getElementById(val);
var submitbtn = $("input[type='submit']");
textbox.disabled = !(checkbox.checked);
if (checkbox.checked) {
submitbtn.attr("disabled", true);
}
else{
textbox.value = "";
}
}
现在我担心的是第二个剧本。
function checkValue(id){
var value = document.getElementById(id).value;
var checkboxes = $("input[type='checkbox']");
// this does not work: var textbox= $("input[name='request-quantity[]']"); ????
if (value == "") {
checkboxes.attr("disabled", true); //this works
checkboxes.checked = false; // this does not work, please if you could answer this one
// for me also, it would be a big help.
// clear textbox
// disable textbox
}
else{
checkGroup();
}
}
我想要做的是获取所有名为request-quantity的文本框(这是一个带有指定索引的数组)并清除并禁用它,就像第一个脚本一样。但我不知道如何访问该元素。
答案 0 :(得分:0)
$('input[name^="request-quantity"]')
是获取名称以“请求数量”开头的商品的选择器。