我正在嘗試顯示復選框值,例如數據庫是否包含以下內容 Array( [0] => Array ( [userid] => 868 [username] => Pavanasri [firstname] => Pavana [email] => [email protected] [signupdate] => 2020-07-13 [add_topic_priv] => Y [add_subject_priv] => Y [add_post_priv] => Y [add_note_priv] => Y [add_disable_priv] => N [add_notifications_priv] => Y ) [1] => Array ( [userid] => 785 [username] => sam123 [firstname] => sam [email] => [email protected] [signupdate] => 2020-07-23 [add_topic_priv] => Y [add_subject_priv] => Y [add_post_priv] => Y [add_note_priv] => Y [add_disable_priv] => N [add_notifications_priv] => Y ))所以這里我有一些從數據庫獲取的字段,前 5 個字段顯示在表中。但是對于復選框值,如何使用 jquery 在前端顯示選中的值 [y]。這是 jquery 代碼。 window.fillData = function(){ alert("memberslist"); var gid = $("#proid").val(); $.ajax({ type:"POST", dataType:"json", url:"memberslist.php", data:{ gid:gid, action:"membersList", }, success : function(response) { if(response.status=="1") { response.data.forEach(function(item) { if (item.add_topic_priv =="Y") { $("#topic").is(":checked"); }在上面的代碼中,我試圖打印字段,但到達復選框時,它沒有顯示檢查“topic”的 id。我們如何通過 jQuery 獲取 html 中的檢查值。這樣我就可以申請到其他領域。輸出我想要的
1 回答

天涯盡頭無女友
TA貢獻1831條經驗 獲得超9個贊
去檢查
$("#topic").prop("checked", true);
取消選中
$("#topic").prop("checked", false);
編輯[包含稍后詢問的代碼]
if(response.status=="1")
{
response.data.forEach(function(item, index) {
....
row += "<td> <input type=checkbox id=topic" + index + "name=example2 class=td-check-box> </td>";
....
$("#tableid").append(row);
if (item.add_topic_priv =="Y")
{
$("#topic" + index).is(":checked");
}
})
}
},
- 1 回答
- 0 關注
- 106 瀏覽
添加回答
舉報
0/150
提交
取消