0

我希望在现成的电子商务平台上触发多个添加到购物篮按钮。服务器使用以下脚本生成添加到购物篮按钮:

按钮 1:

<a id="productRepeater_ctl00_btnAddToBasket" class="btn addbutton" href="javascript:__doPostBack('productRepeater$ctl00$btnAddToBasket','')">add to basket</a>

按钮 2:

<a id="productRepeater_ctl01_btnAddToBasket" class="btn addbutton" href="javascript:__doPostBack('productRepeater$ctl01$btnAddToBasket','')">add to basket</a>

按钮 1:

<a id="productRepeater_ctl02_btnAddToBasket" class="btn addbutton" href="javascript:__doPostBack('productRepeater$ctl02$btnAddToBasket','')">add to basket</a>

平台脚本:

//<![CDATA[
var theForm = document.forms['buyoffpage'];
if (!theForm) {
    theForm = document.buyoffpage;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>

我希望能够通过单击一个单独的 jQuery 按钮来提交所有这些按钮。到目前为止我得到的脚本只提交了第一个:

$("body").append('<div id=\"submitAll\"><a href=\"#\">HIT ME</a></div>');
$('#submitAll').click(function(e) {
   __doPostBack('productRepeater$ctl00$btnAddToBasket', 'productRepeater$ctl01$btnAddToBasket','productRepeater$ctl02$btnAddToBasket');
    }); 
4

2 回答 2

0

如果表单不是通过 AJAX 或类似方式提交的,您将无法提交所有表单。如果您使用的是 AJAX,您可以执行以下操作:

var submitAll = $('<a href="javascript:;" />').html('HIT ME').click(function(){

      $('.addbutton').trigger('click');

});
$('body').append($('<div id="submitAll" />').append(submitAll));
于 2012-04-12T15:06:28.650 回答
0

你会想做这样的事情......(你必须玩这个,因为它不是一个完整的解决方案)

function submitAll(){
  //your submit code
}

$(".btn.addbutton").each(function(a){
  //first clean up old junk
  a=$(a)
  a.removeAttr('href');
  //add a custom event call
  a.bind('submitAll', submitAll )
});

//fire custom events
$('#submitAll').trigger('submitAll')
于 2012-04-12T15:11:11.513 回答