我有一個ASP.NET的WebForms應用程序看起來像這樣一種形式表單字段重複:如何通過使用jQuery/JavaScript的
<div id="signinForm">
<div class="form-inline form-group-sm">
<div class="input-group">
<label for="MemberName" class="sr-only">Email Address :</label>
<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
<input type="email" required id="MemberName" placeholder="Email Address" class="form-control">
</div>
<div class="input-group">
<label for="Password" class="sr-only">Password :</label>
<input type="password" required id="Password" placeholder="Password" class="form-control">
</div>
<button id="signInBtn" class="btn-sm btn-primary" autocomplete="off" data-loading-text="Wait...">Login</button>
</div>
</div>
我想建立從表單字段的JSON對象傳遞給Web服務,而現在我使用的是這樣的:
var formData = {};
$(signinForm).find(':input').each(function() {
formData[this.name] = this.value;
});
var json = JSON.stringify({ NewMember: formData });
如果我檢查內置JSON對象,表單字段中不包含的對象 - 他們是空白的(「」)。我在代碼中遺漏了什麼,我必須實現我想要的功能,即將表單字段的名稱/值對作爲創建的JSON對象的一部分包含在內?
你說得對!把這個「輸入」從「輸入」中找出來是個訣竅。非常感謝你! Upvote並接受答案。我很感激! –
@DanielAnderson我的榮幸。快樂編碼:)) –