如何使用javascript找到屏幕宽度和屏幕高度
答案 0 :(得分:1)
我认为这样做不好 JQuery的:
var Width = $(window).width();
var Height = $(window).height();
答案 1 :(得分:1)
我相信你正在寻找这个
// Get the window dimensions
var $window = $(window);
var wWidth = $window.width();
var wHeight = $window.height();
答案 2 :(得分:1)
使用
$(function() {
$.post(window.location, { width: screen.width, height:screen.height }
});
答案 3 :(得分: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">
答案 4 :(得分: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 }
});