【发布时间】:2020-07-31 08:59:51
【问题描述】:
我正在尝试显示复选框值,例如数据库是否包含以下内容
Array
(
[0] => Array
(
[userid] => 868
[username] => Pavanasri
[firstname] => Pavana
[email] => pavan@gmail.com
[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] => sa@gmail.com
[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");
}
var row = "<tr>";
row += "<td id=tid>" + item.username + "</td>";
row += "<td id=firstname>" +item.firstname+ "</td>";
row += "<td id=email>" + item.email + "</td>";
row += "<td id=signupdate>" + item.signupdate + "</td>";
row += "<td id=invitedon>" + item.invitedon + "</td>";
row += "<td id=acceptedon>" + item.acceptedon + "</td>";
row += "<td> <input type=checkbox id=topic name=example2 class=td-check-box> </td>";
row += "<td> <input type=checkbox id=subject name=example2 class=td-check-box> </td>";
row += "<td> <input type=checkbox id=post name=example2 class=td-check-box> </td>";
row += "<td> <input type=checkbox id=note name=example2 class=td-check-box> </td>";
row += "<td> <input type=checkbox id=disable name=example2 class=td-check-box> </td>";
row += "<td> <input type=checkbox id=notification name=example2 class=td-check-box> </td>";
row += "<td><i id=deletep class=\'fa fa-trash-o\'></i></td>";
row += "</tr>";
$("#tableid").append(row);
})
}
},
error : function(response){
$("#succ_msg").html("<p style=\'color:red;font-weight:bolder;\'>error</p>");
}
});
return false;
}
在上面的代码中,我试图打印字段,但进入复选框时,它没有显示检查“主题”的 id。我们如何通过 jQuery 将检查值获取到 html。所以我可以申请其他领域。
【问题讨论】:
标签: javascript php jquery json ajax