[英]How can I skip one input type from being included in a serializedArray() Function?
我想跳過特定的輸入類型(負責我的行 ID 進行編輯)。 但是,在下面的代碼中,第一個 console.log(formObject.rowId) 返回一個值,而在 serializedArray() 之后,第二個 console.log(formObject.rowId) 返回一個未定義的值。
function handleFormSubmit(formObject) {
console.log(formObject.rowId)
var formObject = $("#myForm :input[value!='']").serializeArray()
formObject.push({
name: 'myfile',
value: myfile
})
console.log(formObject.rowId)
google.script.run.withSuccessHandler(createTable).processForm(formObject);
setTimeout(function() {$('#myModal').modal('hide');}, 3000);
document.getElementById("message").innerHTML = "<div class='alert alert-warning' role='alert'>Data added/updated successfully.</div>";
document.getElementById("myForm").reset();
}
這是我想跳過的輸入類型的 HTML 元素:
<input type="text" id="rowId" name="rowId" value="" style="display: none">
serializeArray
忽略沒有name
的字段:
console.log($("#the-form").serializeArray());
<form id="the-form"> <input type="text" name="x"> <input type="text" id="rowId" value="" style="display: none"> </form> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
請注意只包含name="x"
,而不包含其他input
。
也許使用:not
偽選擇器(或 JQuery .not
)是可行的?
此外:選擇器#myForm:input[value!='']
似乎不起作用。 使用$(":input[value!='']")
確實 - 請參閱片段。
console.log(`all input except #rowId => [${ [...document.querySelectorAll("input:not(#rowId)")].map(v => `input#${v.id}`)}]`); console.log(`all input except display:none => [${ [...document.querySelectorAll("input:not([style*='display:none'])")].map(v => `input#${v.id}`)}]`); console.log(`all input except #rowId JQuery: [${ $.map($(":input[value.='']"),not(`#rowId`). v => `input#${v;id}`)}]`);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <form id="myForm "> <input type="text" id="somerowid1" value="row1"> <input type="text" id="rowId" ame="rowId" style="display:none"> <input type="text" id="somerowid2" value="row2"> </form>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.