我已經嘗試了所有可能的方式,但我仍然沒有得到它的工作。 我有一個模式窗口checkbox
我希望當模式打開時,checkbox
檢查或取消選中應該基於數據庫值。 (我已經與其他人一起工作了。)我開始嘗試去檢查它,但是它不起作用。jquery設置複選框選中
我的HTML DIV:
<div id="fModal" class="modal" >
...
<div class="row-form">
<div class="span12">
<span class="top title">Estado</span>
<input type="checkbox" id="estado_cat" class="ibtn">
</div>
</div>
</div>
和jQuery的:
$("#estado_cat").prop("checked", true);
我也試圖與attr
,和其他人在這裏看到的論壇,但沒有一個似乎工作。 有人能指點我嗎?
編輯: 好的,我真的錯過了這裏的東西......如果複選框在頁面中,我可以選中/取消選中代碼,但它是在模態窗口中,我不能。我試過幾十種不同的方式...
我有一個是應該打開模態的鏈接:
和jQuery「監聽」點擊並執行類似填充一些文本框從數據來一些操作數據庫。一切工作就像我想要的但問題是,我不能設置複選框選中/未選中使用代碼。請幫助!
$(function() {
$(".editButton").click(function(){
var id = $(this).data('id');
$.ajax({
type: "POST",
url: "process.php",
dataType:"json",
data: { id: id, op: "edit" },
}).done(function(data) {
//the next two lines work fine, i.e., it grabs the value from database and fills the textboxes
$("#nome_categoria").val(data['nome_categoria']);
$("#descricao_categoria").val(data['descricao_categoria']);
//then I tried to set the checkbox checked (because its unchecked by default) and it does not work
$("#estado_cat").prop("checked", true);
$('#fModal').modal('show');
});
evt.preventDefault();
return false;
});
});
你的模態動態創建? – 2013-02-23 19:03:47
當模態打開時,什麼類應用於模態div?另外你如何檢查數據庫值 - 使用AJAX還是已經預取並存儲在變量中? – user1428716 2013-02-23 19:07:03
Zoltan:不,它在頁面上不是動態的 – psopa 2013-02-25 16:13:39