嗨,我有一个 Ajax 表单,需要在单击以下按钮时发布:
<div id="divaddtocartbtn">
<input type="image" class="buynow" id="imgaddtocart" alt="Add to Cart" src="http://static.e-talemedia.net/content/images/odditiesaddtobasketbutton.png" />
</div>
但是我也有一个计数器如下:
<div class="box">
<label for="qty">
<abbr title="Quantity">Qty</abbr></label>
<input id="qty" value="0" />
<button id="down" onclick="modify_qty(-1)">-1</button>
<button id="up" onclick="modify_qty(1)">+1</button>
</div>
http://www.codecademy.com/courses/a-simple-counter/0#!/exercises/0 - 简单计数器
但是,由于这是在 Ajax 表单中,当我尝试单击 + 和 - 来增加/减少计数器时,会发生 Ajax 帖子。我如何分离输入,以便 Ajax 帖子仅在添加到购物篮点击时发生?
我在想我需要将计数器放在 Ajax 表单之外,但我需要获取在 ajax 帖子中选择的数量。
Ajax.BeginForm("ThreeInOneBin2", new AjaxOptions() {
HttpMethod = "POST"
});
请参阅下面的完整代码:
<div class="ThreeInOneBin2middle">
<ul>
<% if (Model.ProductNotFound)
{ %>
<!-- List the retailers as we have none in stock -->
<%= Html.WidgetProductNotFoundList(Model) %>
<% }
else
{ %>
<% using (Html.BeginForm())
{%>
<%= Html.AntiForgeryToken() %>
<%= Html.WidgetProductFoundListThreeStageBin2(Model)%>
<div class="stepFour">
<% if (string.IsNullOrEmpty(ViewBag.Confirmation))
{
Ajax.BeginForm("ThreeInOneBin2", new AjaxOptions()
{
HttpMethod = "POST"
});
{ %>
<img src="http://static.e-talemedia.net/content/images/DoveStep3message.png" alt="" />
<%-- This is the quantity--%>
<div class="box">
<label for="qty">
<abbr title="Quantity">
Qty</abbr></label>
<input id="qty" value="0" />
<button id="down" onclick="modify_qty(-1)">
-1</button>
<button id="up" onclick="modify_qty(1)">
+1</button>
</div>
<div id="uandp">
<p>
<input type="text" name="username" class="txtUsername" id="email" value="Username" />
<%= Html.ValidationMessage("Email", "Please enter a valid Email") %>
</p>
<p>
<input type="password" name="password" class="txtPassword" value="Password" />
</p>
</div>
<div id="rightaddtocart">
<div id="divaddtocartbtn">
<input type="image" class="buynow" id="imgaddtocart" alt="Add to Cart" src="http://static.e-talemedia.net/content/images/odditiesaddtobasketbutton.png" />
</div>
</div>
<% } %>
<% }
else
{ %>
<p>
<%-- <%= ViewBag.Confirmation %>--%>
<img class="divAdded" src="http://static.e-talemedia.net/content/images/Basketmessage.png"
alt="Added to Basket" />
</p>
<% } %>
</div>
<% } %>
<% } %>
</ul>
</div>