Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQuery只从radiobutton获取第一个值_Jquery_Html - Fatal编程技术网

JQuery只从radiobutton获取第一个值

JQuery只从radiobutton获取第一个值,jquery,html,Jquery,Html,我有这个html <div> <input type="radio" name="erp_report_type" value="customerinvoice" required> <label for="">Customer Invoice</label> <input type="radio" name="erp_report_type" value="packinglist"> <label

我有这个html

<div>
    <input type="radio" name="erp_report_type" value="customerinvoice" required>
    <label for="">Customer Invoice</label>
    <input type="radio" name="erp_report_type" value="packinglist">
    <label for="">Packing List</label>
    <input type="radio" name="erp_report_type" value="performainvoice">
    <label for="">Performa Invoice</label>
    <input type="radio" name="erp_report_type" value="commercialinvoice">
    <label for="">Commercial Invoice</label>    
</div>
<div>
    <input type="radio" name="erp_productformat" value="description">
    <label for="">Description</label>
    <input type="radio" name="erp_productformat" value="picture">
    <label for="">Picture</label>
    <input type="radio" name="erp_productformat" value="descriptionpicture">
    <label for="">Description &amp; Picture</label>
</div>
问题是变量productFormat将只保存第一个值,即
description
,如果我检查其他两个字段,它不会获取其他值

我仍然是jQuery或JS的不速之客。我哪里出错了?

试试这个

$("input[name='erp_productformat']").each(function(){
    var productFormat = $(this).val()
    if( type == 'customerinvoice') {
    } else if(type == 'packinglist') {
    } else if(type == 'performainvoice') {
    } else if(type == 'commercialinvoice') {
    }
})
尝试更改为:

var productFormat = $("input[name='erp_productformat']").filter(':checked').val();
这将从“erp\U productformat”输入组返回选中的值,然后返回其值。

请重试

each(function() {
而不是

change(function() {

我需要:勾选:),我做过一次,但我忘了:我认为你们甚至不需要过滤器。这就是我所做的var
productFormat=$(“input[name='erp\u productFormat']:checked”).val()
您不需要
.filter()
;你说得对。但是,我永远记不起在
:选中之前是否需要空格,或者如果将空格放入选择器中,是否需要空格。我想给你一些我知道有效的东西,而不是一个不完整的解决方案。坏主意,我希望我的代码使用onchange事件执行,而不是所有的东西。
change(function() {