Javascript 在选中一系列复选框之前禁用链接
我试图找出如何禁用以下链接,直到选择了一系列4或5个复选框Javascript 在选中一系列复选框之前禁用链接,javascript,jquery,checkbox,licensing,Javascript,Jquery,Checkbox,Licensing,我试图找出如何禁用以下链接,直到选择了一系列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://exam
<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/';"/>
假设您引用了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" />
等等。你可以这样做
<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/';}"/>
如果您有以下表格:
<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;
}
}
}
$(函数(){
$(“.my form”).submit(函数(){
if($(“.my表单输入[类型=复选框]:选中”).length<1)
{
警报(“必须至少选择一个复选框才能继续。”);
返回false;
}
}
}
4或5?哪一个?4或5?检查哪一个或只是检查一定数量的图像有关系吗?好的,实际上是12个。为了提交图像,必须检查所有这些图像。
$(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;
}
}
}