问问题
1103 次
1 回答
0
因此,您可以做的updateQty
是拥有一个对列表中的所有产品都正确的函数,只需创建一个通过相对路径查找所有必要元素的函数。
//in this function the context is the element, so the
//`this` variable can be used rather than a param
//for the product id
function updateQty() {
//show the update link
var parent = this.parentNode;
//assumes only the update text uses the class bodyTiny, and that there
//is only one element using it. obviously making this invariant true
//would be trivial by adding a different class name
var updateText = parent.getElementsByClassName("bodyTiny")[0];
updateText.style.display = 'block';
var updateLink = updateText.parentNode
, updateHref = updateLink.href;
//next we find the current quantity and replace it with the input
updateHref = updateHref.replace(/qty=(\d*)/, 'qty='+this.value);
//then we set the link element's attribute
updateLink.href = updateHref;
//now when you mouse over the link you should see the url has changed
}
您还可以将您的表单设置POST
为等效数据,然后我猜在服务器端您将拥有您的OnGetPage
和OnPostback
两者都委托给相同的方法,其参数要么从查询字符串中解析出来,要么从发布数据中解析出来。
您可以看到它在 jsfiddle 上运行。希望这会有所帮助!
于 2013-01-19T00:06:36.097 回答