javascript - 如何确定在php中使用screen.width的变量window.width?

标签 javascript php jquery variables

我需要知道 jQuery 或 JavaScript 中的屏幕尺寸,并且我需要在 PHP 变量中打印该值来确定是否显示某个项目。

var width = $(window).width();

if (width <= 1024) {
   ///// How can I set a variable here and use it with PHP?
}

谢谢!

最佳答案

伙计,你永远不会从你的php代码中获取窗口宽度,php代码在你的网络服务器上执行,你只能从用户浏览器上运行的javascript获取窗口大小,你只需要找到一种发送宽度的方法你从 js 到你的 php 代码,就是这样!

示例代码:

function myJavascriptFunction() { 
  var javascriptVariable = "John";
  window.location.href = "YOURPHPFILE.php?name=" + javascriptVariable; 
}

关于javascript - 如何确定在php中使用screen.width的变量window.width?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33769341/

相关文章:

javascript - 在此代码中要执行的三元运算符的真值在哪里?

javascript - mousedown 事件可以在循环中间发生吗?

php - 如何在html选项标签中添加php?

php - RETS MLS 和 RETS 客户端

javascript - JQuery 在 div 中选择多个 img 之一

jquery - 高度侧边栏不是 100%

javascript - 如何将 JQuery 导入自定义 dnn 模块

javascript - Crossfilter.js 按多个分类轴分组

javascript - 如果从未进行关闭握手,WebSockets 不会在 IE 上关闭

php - 使用文本区域发布数据是否会自动添加斜杠(转义)文本?