在javascript中获取单选按钮的选中值 [英] Get the checked value of a radio button in javascript
本文介绍了在javascript中获取单选按钮的选中值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
在我的HTML表格中,我想获取表格中每一行的选中值,但即使知道我选择它也会一直返回错误
我尝试过:
Hi
In my HTML table i want to get the checked value for each row in my table, but it keeps returning false even know that i am selecting it
What I have tried:
$(document)
.ready(function () {
var myUrl = $("#myUrl").val();
var arrayDetails = new Array();
var row = 1;
function NewEntry(area, process, value1, value2, value3, comment) {
this.Area = area;
this.Process = process;
this.Value1 = value1;
this.Value2 = value2;
this.Value3 = value3;
this.Comment = comment;
}
// dropdown change
$('#ProList').on('change', function () {
var selectedValue = $('#ProList').val();
$.ajax({
type: "GET",
url: myUrl1,
contentType: "application/json; charset=utf-8",
datatype: JSON,
data: { 'proList': selectedValue },
success: function (result) {
$("#mainData").empty();
$.each(JSON.parse(result), function (i, item) {
var row = i + 1;
$("#mainData").append(
"" +
"" + item.Process + "" +
"" + item.Checks + "" +
"" +
"<div class="btn-group" data-toggle="buttons" "="" +="">" +
"<label class="btn btn-success" "="" +="">" +
"<input type="radio" name="options1" id="green_" + row + "" "="" +="">" +
"<span class="glyphicon glyphicon-ok" "="" +=""></span>" +
"</label>" +
"<label class="btn btn-warning" "="" +="">" +
"<input type="radio" name="options2" id="yellow_" + row + "" "="" +="">" +
"<span class="glyphicon glyphicon-ok" "="" +=""></span>" +
"</label>" +
"<label class="btn btn-danger" "="" +="">" +
"<input type="radio" name="options3" id="red_" + row + "" "="" +="">" +
"<span class="glyphicon glyphicon-ok" "="" +=""></span>" +
"</label>" +
"" +
"<textarea id=" + " '"="" +="" "comments_"="" row="" "'"="" "type="text" placeholder="" class="form-control input-md"></td>" +
"</tr>");
});
},
error: function () {
}
});
});
// submit event
<pre> $("#subButton").click(function () {
var rowCount = $('#mainData >tr').length;
for (var i = 1; i <= rowCount; i++)
{
var areaEntered = document.getElementById("process_" + i).innerText;
var processEntered = document.getElementById("checks_" + i).innerText;
var valueEntered1 = document.getElementById("green_" + i).checked;
var valueEntered2 = document.getElementById("yellow_" + i).checked;
var valueEntered3 = document.getElementById("red_" + i).checked;
var commentEntered = document.getElementById("comments_" + i).value;
var entry = new NewEntry(areaEntered, processEntered, valueEntered1, valueEntered2, valueEntered3, commentEntered);
arrayDetails.push(entry);
}
sendToController();
});
function sendToController() {
$.ajax({
type: "POST",
url: myUrl,
contentType: "application/json; charset=utf-8",
datatype: JSON,
data: JSON.stringify({ methodParam: arrayDetails }),
success: function () {
alert(" Click Ok to return");
},
error: function () {
alert(test);
}
});
}
});</textarea></div>
推荐答案
(文件)
.ready(function(){
var myUrl =
(document) .ready(function () { var myUrl =
(#myUrl)。val();
var arrayDetails = new Array();
var row = 1;
函数NewEntry(area,process,value1,value2,value3,comment){
this.Area = area;
this.Process = process;
this.Value1 = value1;
this.Value2 = value2;
this.Value3 = value3;
this.Comment =评论;
}
//下拉列表更改
("#myUrl").val(); var arrayDetails = new Array(); var row = 1; function NewEntry(area, process, value1, value2, value3, comment) { this.Area = area; this.Process = process; this.Value1 = value1; this.Value2 = value2; this.Value3 = value3; this.Comment = comment; } // dropdown change
('#ProList')。on('change',function(){
var selectedValue =
('#ProList').on('change', function () { var selectedValue =
这篇关于在javascript中获取单选按钮的选中值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文