我正在尝试从表单中选择所有值,但隐藏的值除外。但是使用input:not([type='hidden']),select,textarea
后的事件会从select
标记中选择所有具有隐藏值的值。
按下提交按钮时调用的函数:
function getInfoSectionValues($objSection) {
var objValue = {};
$objSection.find(".info, .info-container").find("input:not([type='hidden']),select,textarea").each(function () {
let strKey = ($(this).attr('data-apiname') !== undefined) ? $(this).attr("data-apiname") : $(this).attr("class");
objValue[strKey] = $(this).val();
});
return objValue;
}
<select class="form-control origin" data-apiname= "Origin" id="originId" placeholder="Test1" required="required">
<option value="" class="hidden">Test1</option>
<repeating the values here passed from the server>
</select>
实际:
Form1: "Pharmacy"
Origin: "Choose Case Origin"
Priority: "Medium"
Status: "Open"
SubStatus: ""
SubStatusReason: ""
Subject: "
预期:
Form1: "Pharmacy"
Origin: ""
Priority: "Medium"
Status: "Open"
SubStatus: ""
SubStatusReason: ""
Subject: "
答案 0 :(得分:0)
要过滤出具有类<select>
选项的hidden
,请使用:
.find("select:not(:has(.hidden)),textarea")
选择器input:not([type='hidden'])
用于非<input>
的{{1}}元素
由于未提供html且解释不力...这是对问题的最佳解释