我有html表我也有按钮当点击按钮重定向到下一页并显示有关传递数据的值,但我想如果表中的任何复选框选中它将不会重定向到下一页它只重定向如果表中的所有复选框都未选中,我试过但不能正常工作可以指导我。
AJAX
<script>
$(document).ready(function() {
$("#redirect").click(function() {
var chkBox=document.getElementById("checkAddress").value;
if (chkBox.checked == 0)
{
var clientid=document.getElementById("client").value;
$.blockUI(
{
message: '<h2>Please wait...</h2><img src="/image/loader.gif" />',
timeout: 2000
});
$.ajax({
type:"post",
data:"clientid="+clientid,
success:function(data){
window.location = '?action=redirectclientpricenotification&clientid='+clientid+'';
$("#result").html(data);
$('.blockUI').hide();
}
});
}
else{
alert("chkBox");
}
});
});
</script>
HTML
<th ><img id='redirect' src="/image/exporttt.png" style="margin:-30 0 0 0px;cursor:pointer;" >
</th>
<td id="CPH_GridView1_Status1'.$rows['net_id'].'" class="updateseleniumroute status1 '.$rows["net_id"].' "><input type="checkbox" style="margin:0 0 0 93px;" id="checkAddress" name="checkAddress" '.$checked_value.' ></td>
答案 0 :(得分:1)
进行以下更改:
var chkBox=document.getElementById("checkAddress");
Donot附加.value,仅在您需要该值时才需要.value。如果剩下的代码都没问题,那就应该这样做。
答案 1 :(得分:1)
试试这个,
var chkBox=document.getElementById("checkAddress");
console.log(chkBox.checked);
答案 2 :(得分:1)
$(document).ready(function() {
$("#redirect").click(function() {
var chkBox=$("#checkAddress");
if (chkBox.attr('checked') != 'checked')
{
var clientid=document.getElementById("client").value;
$.blockUI(
{
message: '<h2>Please wait...</h2><img src="/image/loader.gif" />',
timeout: 2000
});
$.ajax({
type:"post",
data:"clientid="+clientid,
success:function(data){
window.location = '?action=redirectclientpricenotification&clientid='+clientid+'';
$("#result").html(data);
$('.blockUI').hide();
}
});
}
else{
alert("chkBox");
}
});
});
</script>
答案 3 :(得分:1)
尝试使用较少的变量:
<script>
$(document).ready(function () {
$("#redirect").click(function () {
if (document.getElementById("checkAddress").checked) {
$.blockUI({
message: '<h2>Please wait...<img src="/image/loader.gif" /></h2>',
timeout: 2000
});
$.ajax({
type: "post",
data: "clientid=" + document.getElementById("client").value,
success: function (data) {
window.location = '?action=redirectclientpricenotification&clientid=' + document.getElementById("client").value + '';
$("#result").html(data);
$('.blockUI').hide();
}
});
} else {
alert("chkBox");
}
});
});
</script>