首页 >php教程 >PHP开发 >PHP HTML JavaScript MySQL代码如何互相传值的方法分享

PHP HTML JavaScript MySQL代码如何互相传值的方法分享

高洛峰
高洛峰原创
2016-11-25 09:35:421439浏览

1.PHP 

a.PHP -> HTML & JavaScript 

html代码中 

<input type="" readonly="readonly" style=&#39;background-color:#DCDCDC&#39; value=<?php echo $perinfo[ID];?> />


JavaScript代码中 
复制代码 代码如下: 

<script type="text/javascript"> 
var ability=<?php echo JSON($array);?>; 
</script>

b.PHP e09be6022d700e04aeaa85a5f42fdcb2 MySQL 

php代码中 
 代码如下: 

<?php 
$dbcnx = @mysql_connect ( "localhost", "root", "1234" ); 
if (! $dbcnx) { 
echo ("Unable to connect to the " . "database server at this time."); 
exit (); 
} 
if (! @mysql_select_db ( "pms" )) { 
echo ("Unable to locate the joke " . "database at this time."); 
exit (); 
} 
mysql_query ( "SET NAMES &#39;GB2312&#39;" ); 
$q=mysql_query("select * from ability where ALV = 1"); 
while($row=mysql_fetch_array($q)){ 
$array1[] = $row[AName]; 
} 
?>

2.HTML 

a. HTML -> PHP (POST方式) 

html代码中 
复制代码 代码如下: 

<form id="form" name="form" method="POST" action="do.php"> 
<input type="hidden" id="count" name="count" value="1"/> 
<input type="submit" name="Submit" value="Search"/> 
</form>

do.php 文件代码中 
复制代码 代码如下: 

<?php 
echo $_POST[&#39;count&#39;]; 
?>

b. HTML -> JavaScript 


JavaScript代码中 (可获得,可更改) 
复制代码 代码如下: 

<script type="text/javascript"> 
var te = document.getElementById("count"); 
te.value = 1; 
</script>

3.JavaScript 

a. JavaScript -> HTML (通用法, 未验证) 

JavaScript代码中 
 代码如下: 

<script type="text/javascript"> 
function f(){ 
var id = "2"; 
var a = document.getElementById("a"); 
a.href.replace("(n)", id); 
} 
</script>


html代码 
代码如下: 

<a id="a" href="http://www.php1.cn/"> 
  b. JavaScript -> PHP

  通过html的转接 

1.JavaScript代码先给html 
代码如下: 

<script type="text/javascript"> 
var i = 1; 
var te = document.getElementById("count"); 
te.value = i; 
</script>

2.html代码给php 
代码如下: 

<form id="form" name="form" method="POST" action="do.php"> 
<input type="hidden" id="count" name="count" value="1"/> 
<input type="submit" name="Submit" value="Search"/> 
</form>

  3.do.php接收到 
代码如下: 

<?php 
echo $_POST[&#39;count&#39;]; 
?>


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn