如何使用PHP使用javascript? [英] How to use javascript using PHP?

查看:83
本文介绍了如何使用PHP使用javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:

我使用 IF ELSE 创建了一个过滤器,当用户单击BOX A AND BOX B时...然后假设BOX A已经满了,在用户点击保存按钮后,将显示一条确认消息,说明... 你选择的盒子已经满了。你要保存吗?其他项目?

I created a filtering using IF ELSE where when the user click BOX A AND BOX B... Then assuming the BOX A is already full, after the user hit the "SAVE BUTTON", a confirmation message will display saying that... "The Box you chosen is already full. Do you want to save the other items?"

这是我的代码:

<?php
//else if......
    else if($box== "BOX A" && $row[item]  == "100")
    {

        echo "<script type='text/javascript'>";
        echo "var r=confirm('The Box you chosen is already full. Do you want to save the other items?')";
        echo "if (r==true){";
        echo "alert('You pressed OK!')}";
        echo "else{";
        echo "alert('You pressed Cancel!')}";
        echo "</script>";

    }
?>

我遇到代码问题,当我尝试使用进行跟踪时echoenter here;
它在程序读取此代码后始终停止

I have a problem with the code and when I try to trace it using echo "enter here"; its always stop after the program read this code

  echo "<script type='text/javascript'>";

然后它会跳到这里:

 echo "</script>";

结果:

未显示弹出消息...所以我需要的是显示弹出消息,我不知道为什么,为什么它不显示...没有按钮涉及显示确认消息...它将只是通过if if然后如果用户想要继续保存,如果其中一个已满,如果不是他/她将按下取消,则会提示...

its not displaying the pop up message ... So all I need is to display the pop up message and I dont know why, why its not displaying... There is no button involve for the displaying of confirmation message...It will just pass by in if else and then it will prompt up if the user wants to continue the saving if one of the box is already full if not he/she will press the cancel...

注意:
我只是PHP和Javascript的初学者..

NOTE: I'm only a beginner for PHP and Javascript..

提前谢谢。

推荐答案

这是因为你开始一个新的<? / <?php 另一个内的标签

This is because you start a new <? / <?php tag inside another

else if($box== "BOX A" && $row[item]  == "100")
{
    <?php
    echo "<script type='text/javascript'>";
    echo "var r=confirm('The Box you chosen is already full. Do you want to save the other items?')";
    echo "if (r==true){";
    echo "alert('You pressed OK!')}";
    echo "else{";
    echo "alert('You pressed Cancel!')}";
    echo "</script>";
    ?>
}

应该是

else if($box== "BOX A" && $row[item]  == "100")
{
    echo "<script type='text/javascript'>";
    echo "var r=confirm('The Box you chosen is already full. Do you want to save the other items?')";
    echo "if (r==true){";
    echo "alert('You pressed OK!')}";
    echo "else{";
    echo "alert('You pressed Cancel!')}";
    echo "</script>";
}

但我个人觉得

    else if($box== "BOX A" && $row[item]  == "100")
    {
?>
<script>
var r=confirm('The Box you chosen is already full. Do you want to save the other items?')";
if (r==true) {
    alert('You pressed OK!');
} else {
    alert('You pressed Cancel!');
}
</script>
<?
    }

更清晰,更易读。保持javascript不受PHP影响,不要回复它如果你可以避免它。可能很难在6个月内进行调查。

is much cleaner and more readable. Keep javascript out of PHP, dont echo it out, if you can avoid it. It can be hard to survey in 6 months.

这篇关于如何使用PHP使用javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆