【发布时间】:2020-07-14 05:28:54
【问题描述】:
我很困惑!我试图在我的页面上定位一个表单并使用 jQuerys serializeArray() 函数来获取表单的所有值。
<div class="page-width">
<header class="section-header text-center">
<h1 class="section-header__title h2">{{ page.title }}</h1>
</header>
<script>
$(document).ready(function () {
$( "#form" ).submit(function( event ) {
var fields = $( "form" ).serializeArray();
console.log(fields)
event.preventDefault();
});
});
</script>
<div class="grid">
<div class="grid__item medium-up--four-fifths medium-up--push-one-tenth">
<div class="rte">
{{ page.content }}
<form action="#" method="#" id="form">
<fieldset>
<legend>Have you ever felt any of the below symptoms after consuming coffee or tea or other caffeinated beverage (cola, hot chocolate...) Select the boxes that apply.</legend>
<input type="checkbox" id="heartburn" >
<label for="heartburn">Heartburn</label><br/>
<input type="checkbox" id="jitters" >
<label for="jitters">Jitters</label><br/>
<input type="checkbox" id="anxiety" >
<label for="anxiety">Anxiety</label><br/>
<input type="checkbox" id="upset-stomach" >
<label for="upset-stomach">Upset Stomach</label><br/>
<input type="checkbox" id="bathroom" >
<label for="bathroom">Urgent need to go the bathroom</label><br/>
<input type="checkbox" id="heart" >
<label for="heart">Racing Heart</label>
</fieldset>
<input type="submit" value="Submit">
</form>
</div>
</div>
</div>
</div>
现在它记录为一个神秘的表单(我认为这与 Shopifys 模板有关)
如果我将选择器更改为
var fields = $( this ).serializeArray();
它记录为一个空数组。
问题
- 我所针对的这种随机形式是什么?
- 如何定位此页面上的表单?
【问题讨论】:
标签: javascript jquery forms shopify