首页 > 如何把php取出来的值放入js函数中?

如何把php取出来的值放入js函数中?

<html>
<head><title>All Items</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<body bgcolor = "black">

<center>
<font color="white">所有文具</font>

<br><br><br>
<hr>

<br><br><br>


</center>

</body>

<table width="370" border="1">
  <tr>
    <td><img src="1.jpg" width="200" height="200"></td>
    <td><font color = "white">品名:笔记本<br>
        价格:10元<br>
        描述:A4大小,120页<br>
        库存:<script language = "php">//用于查询库存
            mysql_connect("localhost","root","") or die(mysql_error());  
            mysql_select_db("user_info");  
            $sql="select * from inventory where pid='1'";  
            $query=mysql_query($sql);  
            $result = mysql_fetch_array($query);  
            @$num = $result['pnum'];   
            echo $num;
            </script><br>
           购买数量:<input type = "text" size = "5" id = "num"/><br>
        <center>
        <br>
        <input type= "button" value = "加入购物车" onclick= "javascript:test('<?php echo $num?>')"/>
        </center>
        </font>
    </td>
  </tr>
  <tr>
    <td><img src="2.jpg" width="200" height="200"></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><img src="3.jpg" width="200" height="200"></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><img src="4.jpg" width="200" height="200"></td>
    <td>&nbsp;</td>
  </tr>

</table>


<script type="text/javascript">

function Check1(){
  var input = document.getElementById("num");
  if(input.value)
}


</script>



</html>

本人想把php中取出来的商品数量放入js函数中进行库存判断。请问如何实现??本人初学者


你可以直接在 js 中写

var num = <?php echo $num;?>;

你需要知道 PHP 和 js 执行的先后顺序。请踩者告诉我问题所在可以吗,我好改进。


写到一个把值<input type="hidden">的内,然后通过js获取进行判断

【热门文章】
【热门文章】