我有这个网站JQuery的获取从单选
<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 & Picture</label>
</div>
我想基于erp_report_type
更改事件从erp_productformat
取值仅第一个值。这是我用它的jQuery。
$("input[name='erp_report_type']").change(function() {
var type = $(this).val();
var productFormat = $("input[name='erp_productformat']").val();
if(type == 'customerinvoice') {
} else if(type == 'packinglist') {
} else if(type == 'performainvoice') {
} else if(type == 'commercialinvoice') {
}
});
问题是可变的productFormat只能容纳即description
如果我检查其他两个领域不取其他值的第一个值。
我仍然是jQuery或JS的noob。我哪里错了?
我需要:检查:),我做到了一次,我忘了:d –
我不认为你甚至需要筛选此。这是我做var'productFormat = $(“input [name ='erp_productformat']:checked”)。val();' –
你不需要'.filter()';你是对的。但是,我永远不会记得在':checked'之前是否需要一个空格,如果你把它放在选择器中。我想给你一些我熟悉的工作,而不是一个不完整的解决方案。 – arb