Heim  >  Artikel  >  Backend-Entwicklung  >  PHP与javascript实现变量交互的示例代码_PHP教程

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

WBOY
WBOYOriginal
2016-07-21 14:59:521071Durchsuche

本例是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
复制代码 代码如下:



 
 
 


 

 



www.bkjia.comtruehttp://www.bkjia.com/PHPjc/328105.htmlTechArticle本例是PHP和javascript交互的例子,php中的值赋给js变量中,前提是这个php变量必须有值才行,就算是假分支中。 比如php中的$flags在本例中为...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn