我正在开发ASP.Net购物卡应用程序,其中我有一个产品详细信息页面,其中input type="text"
为数量,当用户点击时加入购物车按钮产品将被添加到购物车。在html中获取文本框的值
<input type="text" id="quantity" value="">
<a href="/[email protected]&Quantity=?">Add to Cart </a>
当用户进入在文本框中值时,查询字符串车连杆的应更新。
我正在开发ASP.Net购物卡应用程序,其中我有一个产品详细信息页面,其中input type="text"
为数量,当用户点击时加入购物车按钮产品将被添加到购物车。在html中获取文本框的值
<input type="text" id="quantity" value="">
<a href="/[email protected]&Quantity=?">Add to Cart </a>
当用户进入在文本框中值时,查询字符串车连杆的应更新。
你可以使用这个jquery函数:
$(document).ready(function() {
$("#quantity").change(function (event) {
var quantity = this.value;
$("a[href^='/Cart.html?Id']")
.each(function() {
var index = this.href.lastIndexOf('=');
var newUrl = this.href.substring(0, index);
this.href = newUrl + "=" + quantity;
});
});
});
您应该使用Javascript来实现这一点。尝试使用
document.getElementById['quantity'].value
这应该回到你的文本框
我认为这将是更容易做到这一点的服务器端
<asp:TextBox ID="quantityTextBox" runat="server"></asp:TextBox>
<asp:Button ID="addToCartButton" runat="server" Text="Add to cart" />
然后在后面的代码,你可以重定向的价值用户
protected void addToCartButton_Click(object sender, EventArgs e)
{
string id = "your id";
string url = String.Format("/Cart.html?Id={0}&Quantity={1}", id, quantityTextBox.Text);
Response.Redirect(url, false);
}
那么我怎么能得到它在查询字符串? – Billz
这不是一个完整的答案,请告诉他如何在盒子更换时自动更新查询字符串。 – Aristos
document.location.href =“/[email protected]&Quantity=”+ document.getElementById ['quantity']。value; 这里有谁是shopith的祸。 –