如何在 Javascript 中添加单选按钮?
How to append radio buttons in Javascript?
正在尝试附加单选按钮但显示 [object Object]。我的代码可能有什么问题?
.append('<li>'+JSON.parse(data.responseText).question+' ('+JSON.parse(data.responseText).score+'pts)
'+$.each(JSON.parse(data.responseText).choices, function(key, value){
{{Form::radio("radio", "value", ["class" => "form-control"])}}'
})+' ');
控制台
choices: Array(4)
0: {id: 121, quiz_question_id: 91, choice: "B", created_at: "2019-11-21
05:35:42", updated_at: "2019-11-21 05:35:42"}
1: {id: 122, quiz_question_id: 91, choice: "G", created_at: "2019-11-21
05:35:42", updated_at: "2019-11-21 05:35:42"}
2: {id: 123, quiz_question_id: 91, choice: "C", created_at: "2019-11-21
05:35:42", updated_at: "2019-11-21 05:35:42"}
3: {id: 124, quiz_question_id: 91, choice: "C1", created_at: "2019-11-21
05:35:42", updated_at: "2019-11-21 05:35:42"}
length: 4
$.each 不会 return 文本。您必须在回调中附加文本。请参考以下示例:
HTML:
<label for="search_field">Address</label>
<input type='text' class='address_field' />
<li class="some_class"></li>
Javascript:
$(document).ready(function() {
var arr = [1,2,3];
$.each(arr, function(key,val) {
$('.some_class').append("(" + val + " )<li>sample1</li>");
});
});
正在尝试附加单选按钮但显示 [object Object]。我的代码可能有什么问题?
.append('<li>'+JSON.parse(data.responseText).question+' ('+JSON.parse(data.responseText).score+'pts)
'+$.each(JSON.parse(data.responseText).choices, function(key, value){
{{Form::radio("radio", "value", ["class" => "form-control"])}}'
})+' ');
控制台
choices: Array(4)
0: {id: 121, quiz_question_id: 91, choice: "B", created_at: "2019-11-21
05:35:42", updated_at: "2019-11-21 05:35:42"}
1: {id: 122, quiz_question_id: 91, choice: "G", created_at: "2019-11-21
05:35:42", updated_at: "2019-11-21 05:35:42"}
2: {id: 123, quiz_question_id: 91, choice: "C", created_at: "2019-11-21
05:35:42", updated_at: "2019-11-21 05:35:42"}
3: {id: 124, quiz_question_id: 91, choice: "C1", created_at: "2019-11-21
05:35:42", updated_at: "2019-11-21 05:35:42"}
length: 4
$.each 不会 return 文本。您必须在回调中附加文本。请参考以下示例:
HTML:
<label for="search_field">Address</label>
<input type='text' class='address_field' />
<li class="some_class"></li>
Javascript:
$(document).ready(function() {
var arr = [1,2,3];
$.each(arr, function(key,val) {
$('.some_class').append("(" + val + " )<li>sample1</li>");
});
});