gpt4 book ai didi

javascript - 如何使用带有复选框和文本输入的 "other"选项

转载 作者:行者123 更新时间:2023-11-28 00:04:01 25 4
gpt4 key购买 nike

我试图在单击“outra”时显示文本输入,这意味着复选框上的“其他”选项...我希望它在我单击它时出现,然后它将在数据库中注册该东西。有谁知道如何帮助我吗?

函数代码:

    <label class="checkbox-inline" for="checkboxes-4">
<input type="checkbox" name="checkboxes" id="checkboxes-4" value="5">
Outro
</label>
<input type="text" maxlength="9" class="input-field4" id="input" name="teste">
</td>
</tr>
<script>
$(document).ready(function(){
$('#input').hide();
$(document).on('change', 'input[type="checkbox"]', function(e){
console.log(e)
if (e.target.id == "checkboxes-4" && e.target.checked) {
$('#input').show();
} else {
$('#input').hide();
}
});
});
</script>

<tr>
<th>Doenças</th>
<label class="checkbox-inline" for="checkboxes-7">
<input type="checkbox" name="checkboxes" id="checkboxes-7" value="8">
Outra
</label>
<input type="text" maxlength="9" class="input-field4" id="input1" name="teste1">
</td>
</tr>

<tr>
<th>Contacto em caso de emergência</td>
<td><input type="text" name="contacto_emergencia" value="<?php echo $contacto_emergencia;?>"/></td>
</tr>

</table>
<br>
<p align=right>
<button type="submit" value="Alterar">Alterar</button>
<button type="cancel" onclick="window.location='http://donutsrool.pt/ficha_aluno.php';return false;">Cancelar</button>
</p>
</form>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$('#input1').hide();
$(document).on('change', 'input[type="checkbox"]', function(e){
console.log(e)
if (e.target.id == "checkboxes-7" && e.target.checked) {
$('#input1').show();
} else {
$('#input1').hide();
}
});
});
</script>

最佳答案

您使用的是框架还是什么?您可能想要添加一个函数来检查复选框是否被选中。从您的标签来看,我会提供一个 JQuery 建议。

完成该任务的 JQuery 可能如下所示:
$('#checkboxes-4').is(":checked")

然后您将有条件地显示您的文本输入。所以也许:

if ($('#checkboxes-4').is(":checked")) {
$('#id_of_textbox').hide();
} else {
$('#id_of_textbox').show();
}

关于javascript - 如何使用带有复选框和文本输入的 "other"选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55819554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com