【发布时间】:2017-01-28 13:47:20
【问题描述】:
我正在尝试让 jquery-store-locator-plugin 的第 2 版在动态生成的位置结果页面上工作,但收效甚微。
问题是我每个位置都有一个表单,我不确定如何在单击提交按钮时将插件连接到表单。有人可以帮我吗?
目前,我只是运行在以下位置找到的演示:
https://bjornblog.com/storelocator/v2/
在容器中,有一个表格:
<div class="bh-sl-container">
<div id="page-header">
<h1 class="bh-sl-title">Using Chipotle as an Example</h1>
<p>I used locations around Minneapolis and the southwest suburbs. So, for example, Edina, Plymouth, Eden Prarie, etc. would be good for testing the functionality.
You can use just the city as the address - ex: Edina, MN.</p>
</div>
<div class="bh-sl-form-container">
<form id="bh-sl-user-location" method="post" action="#">
<div class="form-input">
<label for="bh-sl-address">Enter Address or Zip Code:</label>
<input type="text" id="bh-sl-address" name="bh-sl-address" />
</div>
<button id="bh-sl-submit" type="submit">Submit</button>
</form>
</div>
<div id="bh-sl-map-container" class="bh-sl-map-container">
<div id="bh-sl-map" class="bh-sl-map"></div>
<div class="bh-sl-loc-list">
<ul class="list"></ul>
</div>
</div>
在演示中,storeLocator() 函数在页面底部被调用(而我想在按钮单击或表单提交时调用它)。
$(function() {
$('#bh-sl-map-container').storeLocator();
});
在我的 JSP 页面中,我有一个在表格行中插入表单的循环:
<tbody>
<c:forEach var="product" items="${productList}" varStatus="loop">
<tr>
<td class="product_name"><a href="${product.detailsLink}" target="_blank">${product.name}</a></td>
<td class="thumb"><a href="${product.detailsLink}" target="_blank"><img src="${product.imagePath}" alt="${product.name}" /></a></td>
<td class="desc">${product.desc}</td>
<td class="price">${product.price}</td>
<td class="">
${product.storeName}
<div id="frmContainer${loop.index}">
<form id="frmMapIt${loop.index}" class="map_it" onsubmit="go($('#frmContainer${loop.index}'), 'frmMapIt${loop.index}', 'bh-sl-address${loop.index}')">
<input type="text" id="bh-sl-address${loop.index}" name="bh-sl-address${loop.index}" />
<button id="bh-sl-submit${loop.index}" type="submit">Map it!</button>
</form>
</div>
</td>
</tr>
</c:forEach>
</tbody>
</table>
这是调用 storeLocator 函数的函数:
function go(formContainer, formID, addressID) {
$('#bh-sl-map-container').storeLocator({
'dataType': 'json',
'dataLocation': 'data/locations.json',
'slideMap': false,
'modal': true,
'formContainer': formContainer,
'formID': formID,
'addressID': addressID
});
}
谢谢!
罗伯
【问题讨论】:
标签: javascript jquery forms jsp jquery-plugins