$(window).width(); //瀏覽器當(dāng)前窗口可視區(qū)域?qū)挾?/p>
10余年的鐘山網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。全網(wǎng)整合營銷推廣的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整鐘山建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。創(chuàng)新互聯(lián)從事“鐘山網(wǎng)站設(shè)計”,“鐘山網(wǎng)站推廣”以來,每個客戶項目都認真落實執(zhí)行。
$(document).width();//瀏覽器當(dāng)前窗口文檔對象寬度
$(document.body).width();//瀏覽器當(dāng)前窗口文檔body的寬度
$(document.body).outerWidth(true);//瀏覽器當(dāng)前窗口文檔body的總寬度 包括border padding margin
然后把獲得總寬度除于2就行了
var kuan=$(window).width()/2;
script type="text/javascript"
$(document).ready(function() ? ?
{
alert($(window).height()); //瀏覽器當(dāng)前窗口可視區(qū)域高度
alert($(document).height()); //瀏覽器當(dāng)前窗口文檔的高度
alert($(document.body).height());//瀏覽器當(dāng)前窗口文檔body的高度
alert($(document.body).outerHeight(true));//瀏覽器當(dāng)前窗口文檔body的總高度 包括
border padding margin
alert($(window).width()); //瀏覽器當(dāng)前窗口可視區(qū)域?qū)挾?/p>
alert($(document).width());//瀏覽器當(dāng)前窗口文檔對象寬度
alert($(document.body).width());//瀏覽器當(dāng)前窗口文檔body的高度
alert($(document.body).outerWidth(true));//瀏覽器當(dāng)前窗口文檔body的總寬度 包括
border padding margin
alert(screen.height);//顯示器分辨率,只能用JavaScript代碼獲取
alert(screen.width);
})
/script
網(wǎng)頁可見區(qū)域?qū)挘?document.body.clientWidth
網(wǎng)頁可見區(qū)域高: document.body.clientHeight
網(wǎng)頁可見區(qū)域?qū)挘?document.body.offsetWidth (包括邊線的寬)
網(wǎng)頁可見區(qū)域高: document.body.offsetHeight (包括邊線的高)
網(wǎng)頁正文全文寬: document.body.scrollWidth
網(wǎng)頁正文全文高: document.body.scrollHeight
網(wǎng)頁被卷去的高: document.body.scrollTop
網(wǎng)頁被卷去的左: document.body.scrollLeft
網(wǎng)頁正文部分上: window.screenTop
網(wǎng)頁正文部分左: window.screenLeft
屏幕分辨率的高: window.screen.height
屏幕分辨率的寬: window.screen.width
屏幕可用工作區(qū)高度: window.screen.availHeight
這個是文件源代碼
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
""
html
head
meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
title/title
script src="lib/jquery-1.6.min.js" type="text/javascript"/script
script src="lib/jquery.validate.js" type="text/javascript"/script
script src="lib/jquery.validate.messages_cn.js" type="text/javascript"/script
style type="text/css"
* { font-family: Verdana; font-size: 96%; }
label { width: 10em; float: left; }
label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
p { clear: both; }
.submit { margin-left: 12em; }
em { font-weight: bold; padding-right: 1em; vertical-align: top; }
/style
script type="text/javascript"
$(document).ready(function(){
$("#commentForm").validate({
rules: {
username: {
required: true,
minlength: 2
},
email: {
required: true,
email: true
},
url:"url",
comment: "required"
}
});
});
/script
/head
body
form class="cmxform" id="commentForm" method="get" action=""
fieldset
legend一個簡單的驗證帶驗證提示的評論例子/legend
p
label for="cusername"姓名/label
em*/eminput id="cusername" name="username" size="25" /
/p
p
label for="cemail"電子郵件/label
em*/eminput id="cemail" name="email" size="25" /
/p
p
label for="curl"網(wǎng)址/label
em /eminput id="curl" name="url" size="25" value="" /
/p
p
label for="ccomment"你的評論/label
em*/emtextarea id="ccomment" name="comment" cols="22"/textarea
/p
p
input class="submit" type="submit" value="提交"/
/p
/fieldset
/form
/body
/html
現(xiàn)在的問題是 在IE瀏覽器是可以驗證的 在遨游 360等瀏覽器里面直接用瀏覽器打開也是可以驗證的,但是用http訪問, IE下正常,360 遨游等下面就不行了 。
似乎是瀏覽器設(shè)置的問題。我剛開始試也不行,后來把360的網(wǎng)頁設(shè)置那里的網(wǎng)頁內(nèi)容和網(wǎng)頁增強的選項都不選,然后點Internet?選項,把安全級別和隱私級別都設(shè)置為中,就好了。
//獲取屏幕坐標(biāo)
function?cpos(x,?y)?{?this.x?=?x;?this.y?=?y?}
var?getPos?=?(Doc)?=?{
var?docs?=?Doc;
var?pos?=?new?cpos(docs.offsetLeft,?docs.offsetTop);
docs?=?docs.offsetParent;
while?(docs)?{
pos.x?+=?docs.offsetLeft;//不斷疊加與祖先級的距離
pos.y?+=?docs.offsetTop;
docs?=?docs.offsetParent;
}
return?pos;
}
var?foo?=?document.getElementById('控件id');
console.log(getPos(foo));
$(window).height();//是文檔窗口高度
$("div").offset().top//是標(biāo)簽距離頂部高度(沒有到下面的距離,比如$("div").offset().down)
$("div").offset().left//是標(biāo)簽距離右邊高度(沒有到下面的距離,比如$("div").offset().right)
$(document).scrollTop();//是滾動條高度
$("div").height();//是標(biāo)簽高度
你要的高度+$("div").height()+[$("div").offset().top-$(document).scrollTop()]=$(window).height();
經(jīng)過簡單的數(shù)學(xué)變換即可得到你要的值了
獲取頁面某一元素的絕對X,Y坐標(biāo),可以用offset():
var X = $(‘#DivID’).offset().top;
var Y = $(‘#DivID’).offset().left;
獲取相對(父元素)位置:
var X = $(‘#DivID’).position().top;
var Y = $(‘#DivID’).position().left;
通過getBoundingClientRect方法獲取對象位置,包含: left , top , right , bottom 4個參數(shù)值。
分享名稱:jquery獲取屏幕,jquery獲取屏幕高度和寬度
當(dāng)前地址:http://vcdvsql.cn/article12/dsdiggc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、用戶體驗、App開發(fā)、網(wǎng)站制作、App設(shè)計、定制網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)