Jquery 在确认真实返回时启用输入字段
我想启用一个输入字段,该字段仅在选中付款复选框时用于选择付款日期!点击复选框将触发付款确认问题,如果确认,复选框将被选中,输入框将可编辑! 以下是不起作用的代码:Jquery 在确认真实返回时启用输入字段,jquery,html,Jquery,Html,我想启用一个输入字段,该字段仅在选中付款复选框时用于选择付款日期!点击复选框将触发付款确认问题,如果确认,复选框将被选中,输入框将可编辑! 以下是不起作用的代码: <script type="text/javascript"> $(document).ready(function(){ $("#talk").click(function(){ return confirm("Did you pay the tax?"); var isChecke
<script type="text/javascript">
$(document).ready(function(){
$("#talk").click(function(){
return confirm("Did you pay the tax?");
var isChecked = $('#talk').is(':checked');
if(isChecked==true)
{
$("#paydate").html('<input type="text" id="name" placeholder="Enter the Date!" />');
}
});
});
</script>
<div id="paydate">
<input type="checkbox" id="talk" />
<input type="text" id="name" readonly />
</div>
$(文档).ready(函数(){
$(“#对话”)。单击(函数(){
报税表确认(“您纳税了吗?”);
var isChecked=$('#talk')。is(':checked');
如果(isChecked==true)
{
$(“#付款日期”).html(“”);
}
});
});
谢谢你的帮助 试试这个:
if(isChecked==true)
{
var a = confirm("Did you pay the tax?");
if(a == true){
$("#paydate").html('<input type="text" id="name" placeholder="Enter the Date!" />');
}
}
if(isChecked==true)
{
var a=确认(“您纳税了吗?”);
如果(a==true){
$(“#付款日期”).html(“”);
}
}
将代码更改为以下内容
<script type="text/javascript">
$(document).ready(function(){
$("#talk").click(function(){
var isChecked = $('#talk').is(':checked');
if(isChecked==true)
{
if(confirm("Did you pay the tax?"))
$("#paydate").html('<input type="text" id="name" placeholder="Enter the Date!"
/>');
}
});
});
</script>
<div id="paydate">
<input type="checkbox" id="talk" />
<input type="text" id="name" readonly />
</div>
$(文档).ready(函数(){
$(“#对话”)。单击(函数(){
var isChecked=$('#talk')。is(':checked');
如果(isChecked==true)
{
如果(确认(“您纳税了吗?”)
$(“#付款日期”).html(“”);
}
});
});
$(文档).ready(函数(){
$(“#对话”)。单击(函数(){
var isChecked=$('#talk')。is(':checked');
如果(isChecked==true)
{
如果(确认(“您纳税了吗?”)
$(“#付款日期”).html(“”);
}
});
});
示例:无需重新创建元素。
只需删除
readonly
属性:
$("#talk").click(function() {
var isChecked = $('#talk').is(':checked');
if (isChecked == true) {
if (confirm("Did you pay the tax?")) {
$('#name').removeAttr('readonly')
}
}
});
要锁定复选框,如您所评论的,请在
$('#name')之后添加$(this).prop('disabled',true)
。removeAttr('readonly')
是,但一旦选中复选框,我还需要锁定它@分销商:如果用户犯了一个错误并想取消选中它怎么办?无论如何,我更新了我的答案,告诉你怎么做。
$("#talk").click(function() {
var isChecked = $('#talk').is(':checked');
if (isChecked == true) {
if (confirm("Did you pay the tax?")) {
$('#name').removeAttr('readonly')
}
}
});