-2
<?php
require "../db/dbconfig.php";
 $gal=mysql_query("select * from gallery");
 $numrows=mysql_num_rows($gal);
if($numrows>=1)
        {
echo "<form action='delete.php' method='post' name='f2' id='f2'>";
echo '<table id="rqst" style="display:block;" border="0" cellpadding="12" cellspacing="3" width="500px">';
    echo "<tr><th>Tick to select</th><th>Images in Gallery</th></tr>";
    while($row=mysql_fetch_array($gal)
{
    $imgfile=$row['ImgName'];
$Image="<img src=gallery/".$imgfile." width='230px' height='150px'/>";

$img_name=$imgfile;



    echo "<tr>";
    echo "<td><input type='checkbox' name='imgs[]' value='$img_name'></td><td>".$Image."</td>";
    echo "</tr>";   
    }
    echo "<tr>";
    echo "<td colspan='3' align='right'>";
   echo "<input type='submit' value='Delete' name='del'></td>";
    echo "</tr>";
echo "</table>";
echo "</form>";
?>

这是我的代码....这将显示来自画廊的图像和与之关联的复选框。当我单击带有未选中复选框的删除按钮时,警报应该像这样“请检查至少一个复选框”..怎么做?

我的下一个问题是,当我在选中复选框后单击删除按钮时,警报应该像这样=“你要删除吗??”...如果单击确定,则必须删除图像,否则什么也不做...请帮助...提前致谢....

4

2 回答 2

0

检查以下链接以使用 jquery 进行验证:

http://jsfiddle.net/susheel61/U3Unk/2/

<form id="form">
    First name: <input type="checkbox" name="firstname" class="check"><br>
    <button>test</button>
</form>


$("button").on("click",function(e){
    var status = $(".check").is(":checked");
    e.preventDefault();
    if(!status){
        alert("this is not checked");
    }
});
于 2013-06-08T05:26:29.537 回答
0

是的,您可以通过 javascript 或 jquery 来验证您的至少一个复选框是否被选中。因此,为此,您需要为所有复选框提供一个通用类作为示例

<input type="checkbox" name="firstname" class="addchk">

现在在您的提交按钮中调用一个验证此事的javascript函数。

<input type='button' value='Delete' name='del' onclick='delete_checked()' />

现在编写一个函数来验证是否选中了任何复选框。

function delete_checked()
{

     var status = $(".addchk").is(":checked");
     e.preventDefault();
    if(!status){
           alert("this is not checked");
     }
     else
     {
          // SUbmit yout form
     }
}
于 2013-06-08T06:23:36.290 回答