用jQuery在循环中更改bootstrap播放按钮值
我正在尝试根据我从MySQL查询中获得的值来更改单选按钮的位置。该循环多次运行,并在每次迭代中创建一行。 我尝试过:
$("#far_table tbody").sortable("disable");
$("#far_table > tbody").empty();
$.getJSON("gsffar.ajax.php", {
function: 'update_far_table',
Engnum: engnum,
Type: type_toggle,
Travid: travid
})
.done(function(data) {
$(data).each(function()
{
$("#far_table").append('<tr> \
<td class="priority">' + this.priority + '</td> \
<td>' + this.attribute + '</td>\
<td>' + this.responsible + '</td> \
<td><div class="btn-group" id="pass_fail_group" data-toggle="buttons">\
<label class="btn btn-primary active">\
<input class="pass_fail" type="radio" name="options" id="pass" value="pass"> Pass\
</label>\
<label class="btn btn-primary" active>\
<input class="pass_fail" type="radio" name="options" id="fail" value="fail" checked> Fail\
</label>\
</div></td>\
<td><div class="input-group">\
<div class="custom-file">\
<input type="file" class="custom-file-input" id="inputGroupFile01" aria-describedby="inputGroupFileAddon01">\
</div>\
</div></td>\
</tr>');
if (this.pass_fail === "pass"){
$('input:radio[name="options"][value="pass"]').click();
}else{
$('input:radio[name="options"][value="fail"]').click();
}
});
});
}
而且
function update_far_table_input(engnum, type_toggle, travid){
$("#far_table tbody").sortable("disable");
$("#far_table > tbody").empty();
$.getJSON("gsffar.ajax.php", {
function: 'update_far_table',
Engnum: engnum,
Type: type_toggle,
Travid: travid
})
.done(function(data) {
$(data).each(function()
{
var pass="";
var fail="";
if (this.pass_fail === "pass"){
pass="checked";
}else{
fail="checked";
}
$("#far_table").append('<tr> \
<td class="priority">' + this.priority + '</td> \
<td>' + this.attribute + '</td>\
<td>' + this.responsible + '</td> \
<td><div class="btn-group" id="pass_fail_group" data-toggle="buttons">\
<label class="btn btn-primary active">\
<input class="pass_fail" type="radio" name="options" id="pass" value="pass" autocomplete="off" '+pass+'> Pass\
</label>\
<label class="btn btn-primary">\
<input class="pass_fail" type="radio" name="options" id="fail" value="fail" autocomplete="off" '+fail+'> Fail\
</label>\
</div></td>\
<td><div class="input-group">\
<div class="custom-file">\
<input type="file" class="custom-file-input" id="inputGroupFile01" aria-describedby="inputGroupFileAddon01">\
</div>\
</div></td>\
</tr>');
});
});
}
似乎两种方法似乎都起作用。我还想在将来添加第三个位置,因此能够按ID或值指定位置是理想的选择。
I am trying to change a radio button's position based on a value I get back from a mysql query. This loop runs multiple times and creates a row with each iteration.
I have tried:
$("#far_table tbody").sortable("disable");
$("#far_table > tbody").empty();
$.getJSON("gsffar.ajax.php", {
function: 'update_far_table',
Engnum: engnum,
Type: type_toggle,
Travid: travid
})
.done(function(data) {
$(data).each(function()
{
$("#far_table").append('<tr> \
<td class="priority">' + this.priority + '</td> \
<td>' + this.attribute + '</td>\
<td>' + this.responsible + '</td> \
<td><div class="btn-group" id="pass_fail_group" data-toggle="buttons">\
<label class="btn btn-primary active">\
<input class="pass_fail" type="radio" name="options" id="pass" value="pass"> Pass\
</label>\
<label class="btn btn-primary" active>\
<input class="pass_fail" type="radio" name="options" id="fail" value="fail" checked> Fail\
</label>\
</div></td>\
<td><div class="input-group">\
<div class="custom-file">\
<input type="file" class="custom-file-input" id="inputGroupFile01" aria-describedby="inputGroupFileAddon01">\
</div>\
</div></td>\
</tr>');
if (this.pass_fail === "pass"){
$('input:radio[name="options"][value="pass"]').click();
}else{
$('input:radio[name="options"][value="fail"]').click();
}
});
});
}
and
function update_far_table_input(engnum, type_toggle, travid){
$("#far_table tbody").sortable("disable");
$("#far_table > tbody").empty();
$.getJSON("gsffar.ajax.php", {
function: 'update_far_table',
Engnum: engnum,
Type: type_toggle,
Travid: travid
})
.done(function(data) {
$(data).each(function()
{
var pass="";
var fail="";
if (this.pass_fail === "pass"){
pass="checked";
}else{
fail="checked";
}
$("#far_table").append('<tr> \
<td class="priority">' + this.priority + '</td> \
<td>' + this.attribute + '</td>\
<td>' + this.responsible + '</td> \
<td><div class="btn-group" id="pass_fail_group" data-toggle="buttons">\
<label class="btn btn-primary active">\
<input class="pass_fail" type="radio" name="options" id="pass" value="pass" autocomplete="off" '+pass+'> Pass\
</label>\
<label class="btn btn-primary">\
<input class="pass_fail" type="radio" name="options" id="fail" value="fail" autocomplete="off" '+fail+'> Fail\
</label>\
</div></td>\
<td><div class="input-group">\
<div class="custom-file">\
<input type="file" class="custom-file-input" id="inputGroupFile01" aria-describedby="inputGroupFileAddon01">\
</div>\
</div></td>\
</tr>');
});
});
}
Neither approach seems to work. I would also like to add a third position in the future so being able to specify position by id or value would be ideal.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现打破标签的建筑物更容易。
在此片段中,我将附加新行,然后将其添加到表中,其中包含的div为“ jQueryable” 。
我正在使用您的数据来获得一些自由,但您应该能够获得它的要点。
请注意,html元素
id
的s应该是唯一的。将此函数与包含重复ID的行一起用于占位符元素将是一个问题。
I find it easier to break out the building of the labels.
In this snippet I'm appending the new row and then once it's added to the table the containing div is "jQueryable".
I'm taking some liberties with your data but you should be able to get the gist of it.
Be aware, Html element
id
's should be unique.Using this function with rows containing duplicate id's for the placeholder element is going to be a problem.