2011-08-18 51 views
0

我想弄清楚如何禁用以下鏈接,直到選中一系列4或5複選框。禁用鏈接,直到檢查了一系列複選框

<input type="image" src="/wp-content/themes/happy/images/add-to-cart.png" name="Buy" class="wpsc_buy_button" id="product_<?php echo wpsc_the_product_id(); ?>_submit_button" onclick="window.location='http://example.com/store/checkout/';"/> 

謝謝!

我對js和jquery也有些遲鈍,所以請簡單一點。我希望所有代碼都在元素附近,並且不在不同的位置,即使這可能是「首選」方法。

非常感謝。

+1

4 *或* 5?這是什麼? 4或5?並且重要的是哪些被檢查或者只有它們有一定數量? –

+0

好吧,實際上它將會是12.並且必須檢查所有這些以便圖像提交。 – stanparker

回答

0

你可以做這樣的事情

<input type="image" src="/wp-content/themes/happy/images/add-to-cart.png" name="Buy" class="wpsc_buy_button" id="product_<?php echo wpsc_the_product_id(); ?>_submit_button" onclick="if($(this).data("enabled")){window.location='http://example.com/store/checkout/';}"/> 

而且在複選框點擊做到這一點

$("input").click(function(){ 

    //Here check for this checkbox and all other series of checkbox, if they are checked then 
    $("img[name=Buy]").data("enabled", true); 
    //else 
    $("img[name=Buy]").data("enabled", false); 
}); 
0

假設你有jquery引用,改變你的onclick方法,像是;

onclick="if($('.checkboxClass').not(':checked').length > 0) window.location='http://example.com/store/checkout/'; else {alert('please tick all the checkboxes'); return 0}; 

然後添加 「checkboxClass」(或任何類,你選擇),所有的複選框

<input type="checkbox" class="checkboxClass" value="1" /> 
<input type="checkbox" class="checkboxClass" value="2" /> 

等等。

0

如果你有以下形式:

<form method="post" action="" class="my-form"> 
    <p> 
     <input type="checkbox" /> First item 
    </p> 
    <p> 
     <input type="checkbox" /> Second item 
    </p> 
    <p> 
     <input type="image" src="..." /> 
    </p> 
</form> 

使用jQuery檢查表格提交

$(function() { 
    $(".my-form").submit(function() { 
     if ($(".my-form input[type=checkbox]:checked").length < 1) 
     { 
      alert("You must select at least one checkbox to proceed."); 
      return false; 
     } 
    } 
}