0

我目前正在编写一个 php 脚本来检查数组中是否没有图像。如果没有图像,我需要一个消息框(我使用 jquery msgbox),询问您是否要创建没有图像的产品。

如果用户单击是,那么我如何返回 true 以便执行 php 代码?我知道 php 是服务器端,所以我“只是”需要你的建议,这里最好的解决方案是什么。

目前我的代码是这样的:

<?php if(!isset($_POST['img'] //imagearray)){?>

        <script>
            $.msgBox({
                title: "Sure?",
                content: "Add product without images?",
                type: "confirm",
                buttons: [{ value: "Yes" }, { value: "No" }, { value: "Cancel"}],
                success: function (result) {

                if (result == "Yes") {
                    return true;
                }else{
                    return false;
                }
            }
        });
        </script>
<?php } ?>
4

2 回答 2

2

好的,这是一个例子,

<script>
$("#my-super-form").submit(function(event) {
  if($("#id-of-your-image-input").val()=="")
    if(confirm("Add product without image?")) {
      return true;
    } else {
      return false
    }
  }
  return true;
});
</script>

它没有经过测试,但我认为你可以弄清楚它是如何工作的。

于 2012-10-24T08:27:31.577 回答
0

如果您使用 jQuery,您想检查是否在帖子之后设置了图像。

当用户点击发送按钮时,您可以使用您的确认消息框,如果找不到图像^^

它对用户来说更直观。

于 2012-10-24T08:17:36.887 回答