-3

如何使用java脚本查找屏幕宽度和屏幕高度

4

5 回答 5

1

我认为这不能解决 JQuery 的问题:

var Width = $(window).width();
var Height = $(window).height();
于 2013-08-01T12:37:55.183 回答
1

我相信你正在寻找这个

// Get the window dimensions
var $window = $(window);
var wWidth  = $window.width();
var wHeight = $window.height();
于 2013-08-01T12:38:38.350 回答
1

采用

$(function() {
    $.post(window.location, { width: screen.width, height:screen.height }
});
于 2013-08-01T12:39:18.267 回答
1

这是答案

演示

JS

$("#width").val($(window).width());
$("#height").val($(window).height());

HTML

Width<input type="text" name="width" id="width">
Heigth<input type="text" name="height" id="height">
于 2013-08-01T12:47:58.800 回答
1

在中查找高度和宽度%

var getPercent = function(elem){
var elemName = elem.attr("id");
var width = elem.width();
var height = elem.height();
var parentWidth = elem.offsetParent().width();
var percentWidth = Math.round(100*width/parentWidth);

var parentHeight = elem.offsetParent().height();
var percentHeight = Math.round(100*height/parentHeight);

console.log(elemName+"'s width = "+percent+"%");
console.log(elemName+"'s height = "+percent+"%");
}

getPercent($('#content'));

而不是写入post.php将其发布到新页面,window.location而是 PHP 会像这样使用它:

$(function() {
$.post(window.location, { width: screen.width, height:screen.height }
});
于 2013-08-01T12:49:32.180 回答