下面是 index.php 文件中的一个 GetWidth 和 GetHeight 函数的工作原理。(它们不是最终函数,所以不重要。)重要的部分由 /* IMPORTANT HERE */ 标记,我想要完成的是传递我使用 jQuery Window Portal Height / Width 获得的变量并将其传递给 PHP 脚本换句话说,当我从 GetWidth() 获取值时,它应该转到 w=120 或将 120 值替换为当前宽度和高度相同的值。如有语法错误请忽略。
我只想弄清楚如何将值从 jQuery 传递到 PHP 脚本。同样在将来我想添加 resize 方法,以便在调整窗口大小时值将是动态的。
<html>
<head>
<title></title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$(window).resize(function () {
$('#msg').text('Browser (Width : '
+ $(window).width()
+ ' , Height :' + $(window).height() + ' )');
});
$(document).ready(function() {
// DOCUMENT READY
function GetWidth() {
if (self.innerWidth) {
return self.innerWidth;
}
else if (document.documentElement &&
document.documentElement.clientHeight) {
return document.documentElement.clientWidth;
}
else if (document.body) {
return 0;
}
return x;
}
function GetHeight() {
if (self.innerHeight) {
y = self.innerHeight;
}
else if (document.documentElement &&
document.documentElement.clientHeight) {
return
document.documentElement.clientHeight;
}
else if (document.body) {
return 0;
}
return y;
}
// This is for when it first loads.
$('#TEXT').text('W: ' + $(window).width() + ' , H:' + $(window).height() + y);
// This is for when window gets resized.
$(window).resize(function () {
$('#TEXT').text('W: ' + $(window).width() + ' , H:' + $(window).height());
});
// DOCUMENT READY
});
</script>
</head>
<body>
Info Area:<br>
<div id="TEXT"></div>
/* IMPORTANT HERE */
<!-- img src="timthumb.php?src=URL...image.jpg&h=180&w=120" -->
/* IMPORTANT HERE */
</body>
</html>