PHP能否根据JS的判断而赋值变量,详情如下

WBOY
Release: 2016-06-23 14:26:05
Original
923 people have browsed it

PHP JS

var num = document.body.clientWidth;//JS获取屏幕宽度

if(num = 1){

    ?

}else{

    ?

}

pS:根据JS获取屏幕的不同宽度给php变量赋值

回复讨论(解决方案)

你可以把脚本放在php中echo出来。。

不能。
PHP在显示页面的时候就已经编译完成,不能通过JS给他赋值。

你可以用ajax在页面加载完后将值传递给php程序. 

不能~
页面在后端时会把所有php语句处理完但并不执行js,等到把处理后的页面发送到前台,也就是你在浏览器里看到页面的时候,js才开始执行。

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!