Home > Backend Development > PHP Tutorial > PHP与javascript实现变量交互的示例代码_PHP

PHP与javascript实现变量交互的示例代码_PHP

WBOY
Release: 2016-06-01 12:04:00
Original
728 people have browsed it

本例是PHP和javascript交互的例子,php中的值赋给js变量中,前提是这个php变量必须有值才行,就算是假分支中。

比如php中的$flags在本例中为true,如果js中false语句写成:$title_1.innerHTML = "";就会出错,因为$title在php中被赋值为数组

尽管在php的flags=="false";$title是一个字符串,情况是$title是数组,而数组在字符串中也是不能直接显示的。
复制代码 代码如下:
$string = "天上and地下";
$flags = "";
if(strpbrk($string,"and")!=false){
 $title = explode("and",$string);
 $title_1 = $title[0];
 $title_2 = $title[1];
 $flags = "true";
}
else{
 $title = $string;
 $flags = "false";
}
?>

—>html
复制代码 代码如下:


 
 
 


 

 



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template