我正在開發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的禍。 –