cuốn sách gpt4 ai đã làm

javascript - 普通 javascript - 获取选中复选框的值

In lại Tác giả: Walker 123 更新时间:2023-11-28 15:51:00 31 4
mua khóa gpt4 Nike

var vettore = document.getElementById(id_form).elements;


for (var i = 0; i < vettore.length; i++)
{
if (vettore[i].checked)
{
contatore++;

valore_corrente = document.getElementById.elements[i].value;

stringaFileSelezionati+= valore_corrente;

stringaFileSelezionati+= '?';
}
}

if (contatore == 0)
{
alert('Error!!! No file selected!');
trả về sai;
}
khác
{
alert(stringaFileSelezionati);

}

错误所在行:

valore_corrente = document.getElementById.elements[i].value;

我怎样才能得到这个值?

编辑:也许错误是在复选框创建中,因为我未定义:

                                    cell1.innerHTML = ''+vettore_nomi_file[i];

câu trả lời hay nhất

您从检索.checked的同一对象中检索.value:

valore_corrente = vettore[i].value;

该对象是 HTMLInputElement实例。复选框的值反射(reflect)在 giá trị 属性中,就像它是否被选中反射(reflect)在 checked 属性中一样。

这是一个完整的工作示例:Live Copy | Source



<đầu>

Ví dụ












document.getElementById("thebutton").onclick = function() {
var id_form = "theform";
var vettore = document.getElementById(id_form).elements;

var contatore = 0;
var valore_corrente;
var stringaFileSelezionati = "";

for (var i = 0; i < vettore.length; i++)
{
if (vettore[i].checked)
{
contatore++;

valore_corrente = vettore[i].value;

stringaFileSelezionati+= valore_corrente;

stringaFileSelezionati+= '?';
}
}

if (contatore == 0)
{
alert('Error!!! No file selected!');
trả về sai;
}
khác
{
alert(stringaFileSelezionati);

}

};

Xem sitemap của VNExpress

关于javascript - 普通 javascript - 获取选中复选框的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20632103/

31 4 0
Đề xuất bài viết: javascript - 在 angularJS 中通过字符串比较检查 Json 对象
Đề xuất bài viết: javascript - JQuery 无法找到选择列表
Đề xuất bài viết: html - Bootstrap Grid系统连续多个div
Đề xuất bài viết: javascript - jQuery:事件 "mouseover"-类似
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Các bài viết phổ biến trên toàn bộ trang web
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com