3

初心者なのでルール違反で失礼します。クリックすると特定の値が URL に追加される一連のボタンを作成しようとしています。アイデアは、人が最後にリンクをクリックしたときに、2 つの変数のどちらを渡す必要があるかを調べたいということです。

これが私のコードです:

 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
jQuery(function(){
  var product1 = 'productId=1&productQuantity=1';
  var product2 = 'productId=2&productQuantity=1';
  var carturl = 'http://cart.net?clearCart=true';
  jQuery(function(){
    jQuery("#Product1Yes").click(function () {
      jQuery("#Product2").show("fast");
      jQuery("#Product1").hide("fast");
    });
    jQuery('a#upsell').attr('href', function() {
      return carturl + '&' + product1;
    });
    jQuery("#Product1No").click(function () {
      jQuery("#Product2").show("fast");
      jQuery("#Product1").hide("fast");
    });
    jQuery("#Product2Yes").click(function () {
      jQuery("#Product3").show("fast");
      jQuery("#Product2").hide("fast");
    });
    jQuery('a#upsell').attr('href', function() {
      return carturl + '&' + product2;
    });
    jQuery("#Product2No").click(function () {
      jQuery("#Link).show("fast");
      jQuery("#Product2").hide("fast");
    }); 
  });
});
</script>

<div id="Product1">
    <button class="btn btn-primary" id="Product1Yes">Yes</button>
    <button class="btn btn-danger" id="Product1No">No</button>
</div>

<div id="Product2">
    <button class="btn btn-primary" id="Product2Yes">Yes</button>
    <button class="btn btn-danger" id="Product2No">No</button>
</div>

<div id="Link">
    <a id='upsell' href='#'>Click here to check out</a>
</div>

表示/非表示機能が機能せず、リンクが正しく作成されていないと思うため、何かが足りないと思います。考え?

4

1 に答える 1

1

ここでjsFiddle。

<div id="Produc1"><div id="Product1">あなたのHTMLにあるはずです。

また、いくつかの右中括弧がありませんでした:

var product1 = 'productId=1&productQuantity=1';
var product2 = 'productId=2&productQuantity=1';
var carturl = 'http://cart.net?clearCart=true';
jQuery(function(){
  jQuery("#Product1Yes").click(function () {
    jQuery("#Product2").show("fast");
    jQuery("#Product1").hide("fast");
  });
  jQuery('a#upsell').attr('href', function() {
    return carturl + '&' + product1;
  });
  jQuery("#Product1No").click(function () {
    jQuery("#Product2").show("fast");
    jQuery("#Product1").hide("fast");
  });
  jQuery("#Product2Yes").click(function () {
    jQuery("#Link").show("fast");
    jQuery("#Product2").hide("fast");
  });
  jQuery('a#upsell').attr('href', function() {
    return carturl + '&' + product2;
  });
  jQuery("#Product2No").click(function () {
    jQuery("#Link").show("fast");
    jQuery("#Product2").hide("fast");
  });
});
于 2013-05-26T16:05:48.840 に答える