如何在javascript中使用PHP变量值?
我正在为我的web应用程序使用PHP、HTML和Javascript。 现在我对下面的代码有一个小问题如何在javascript中使用PHP变量值?,php,javascript,jquery,html,Php,Javascript,Jquery,Html,我正在为我的web应用程序使用PHP、HTML和Javascript。 现在我对下面的代码有一个小问题 $e=$_POST['users']; //$e should have either employee_id or a string "All" 现在,根据这个值,我必须将一个HTML按钮重定向到一个特定的页面。 就我而言 if $e=="employee_id(or may be you could say that $e!="All")" then redirect the page
$e=$_POST['users']; //$e should have either employee_id or a string "All"
现在,根据这个值,我必须将一个HTML按钮重定向到一个特定的页面。
就我而言
if $e=="employee_id(or may be you could say that $e!="All")" then redirect the page to salary_report.php
并且如果$e==“All”,那么页面应该重定向到salary\u report\u combined.php
我当前的按钮代码如下:
<input type="button" class="btn btn-primary" id="leavere" name="leavere" value="Back to Salary Report" onclick="location.replace('salary_report.php')"></input>
因此,目前它只重定向到salary_report.php文件。我的问题是如何应用基于PHP变量值的条件并执行HTML代码?现在你能帮我解决这个问题吗。提前通知。您可以这样做:
if($e == "All"){
$redirectTo = "salary_report_combined.php";
}
else{
$redirectTo = "salary_report.php";
}
在您的按钮中:
<input type="button" class="btn btn-primary" id="leavere" name="leavere"
value="Back to Salary Report" onclick="location.replace('<?php echo $redirectTo ?>')"></input>
希望这有帮助 您可以这样做:
if($e == "All"){
$redirectTo = "salary_report_combined.php";
}
else{
$redirectTo = "salary_report.php";
}
在您的按钮中:
<input type="button" class="btn btn-primary" id="leavere" name="leavere"
value="Back to Salary Report" onclick="location.replace('<?php echo $redirectTo ?>')"></input>
希望这有帮助 您还可以按如下方式使用:
var $e = <?php echo $_POST['users'] ?>;
var$e=;
然后在条件中使用$e。您也可以按如下方式使用:
var $e = <?php echo $_POST['users'] ?>;
var$e=;
然后在条件中使用$e。作为问题的解决方案,您可以将重定向url存储到php变量中,然后在javascript代码段中访问php变量的值 例如
作为问题的解决方案,您可以将重定向url存储到php变量中,然后在javascript代码段中访问php变量的值
例如
我只是做一个链接,让它看起来像一个按钮,然后根据你的条件用PHP打印href
。我只是做一个链接,让它看起来像一个按钮,然后根据你的条件用PHP打印href
。