我正在编写一个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 } ?>
答案 0 :(得分: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>
它没有经过测试,但我认为你可以弄清楚它是如何工作的。
答案 1 :(得分:0)
如果您使用jQuery,则需要检查是否在帖子后设置了图像。
当用户点击发送按钮时,如果找不到图像,则可以使用确认消息框^^
对用户来说更直观。