javascript_BOM基础_ZHOU125disorder_

BOM基础

window

  1. screen存放浏览器的屏幕信息

  2. navigator描述当前的浏览器

  3. locationwindow对象的一部分,可以判断历史记录数量

  4. history保存浏览器历史记录信息

  5. frames窗口或框架内的结构

BOM

BOM (Browser Object Model)     浏览器对象模型
操作浏览器         js对浏览器的各种操作的对象

open()方法打开指定窗口

		window.open("https://www.baidu.com","_self","width=456,height=456,top=0,left=0");
		window.open("路径","打开方式","窗口的大小和位置");//当打开方式为_self时窗口的大小和位置没用
		打开的方法和a标签的target一样为(_self或_blank)`默认为新窗口打开`

close()关闭关闭指定的窗口

	new_window = window.open("https://www.baidu.com","_self","width=456,height=456,top=0,left=0");
	new_window.close();

navigator对象

        // navigator对象
        console.log("浏览器代码名称:"+navigator.appCodeName);
        console.log("浏览器名称:"+navigator.appName);
        console.log("浏览器版本:"+navigator.appVersion);

screen对象

        //  screen对象
        //  获取屏幕信息
        //  screen屏幕的宽高
        console.log(screen.width);
        console.log(screen.height);
        //  screen屏幕的宽高    avail不包括窗口任务栏
        console.log(screen.availHeight);
        console.log(screen.availWidth);

History对象

        //History对象
        history.forward();//下一页
        history.back();//上一页
        history.go(0);//刷新
        history.go(1);//下一页
        history.go(-1);//上一页
        history.go(2)//下二页
        history.go(-2)//上二页

location对象

    // location对象   获取当前页面的地址,并把浏览器重新定向到一个新的页面;
    //人话:就是进行赋值,和open类似;
window.location.href = "https://www.baidu.com";

刷新页面

            // window.location.href = window.location.href;
            // window.location.reload();

工作区域尺寸

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>工作区域尺寸</title>
    <style>
    *{
        margin: 0;
        padding: 0;
        list-style: none;
    }

    div{
        width: 256px;
        height: 256px;
        overflow: auto;
    }
    </style>
</head>
<body>
    <div>
        卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西
        卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西
        卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西
        卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西
        卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西
        卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西
        卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西
        卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西
        卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西
        卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西卡卡西
    </div>

    <script>
        var div=document.getElementsByTagName("div")[0];
        // client系列   可以理解为可视区域宽高          不把滚动条和边框算在内
        console.log(div.clientWidth);
        console.log(div.clientHeight);
        // offset系列   width+padding+border           包含边框和滚动条
        console.log(div.offsetWidth);
        console.log(div.offsetHeight);
        // scroll系列   不包含滚动条和border            实际的宽高,包括隐藏元素的宽高
        console.log(div.scrollWidth);
        console.log(div.scrollHeight);
        // 获取浏览器窗口的尺寸     不包括控制台
        console.log(window.innerWidth);
        console.log(window.innerHeight);
        // HTML文档所在窗口宽高
        console.log(document.documentElement.clientWidth);
        console.log(document.documentElement.clientHeight);
        //兼容写法
        // document.body.clientWidth
        // document.body.clientHeight
        var width=document.documentElement.clientWidth||document.body.clientWidth;
        var height=document.documentElement.clientHeight||document.body.clientHeight;
        console.log(width);
        console.log(height);
        // onscroll滚动条事件
        // scrollTop到顶部的距离
        // scrollLeft到左边的距离
        div.onscroll=function(){
            console.log(div.scrollTop);
            console.log(div.scrollLeft);
        }
    </script>
</body>
</html>
offset与定位父级的距离;

        *{
            margin: 0px;
            padding: 0px;
            list-style: none;
        }
        .father{
            width: 456px;
            height: 456px;
            background-color: #ddd;
            position: relative;
            top: 20px;
            left: 20px;
        }

        .son{
            width: 256px;
            height: 256px;
            position: absolute;
            background-color: #096;
            top: 100px;left: 100px;
        }

    <div class="father">
        <div class="son"></div>
    </div>

    <script>
        var son=document.getElementsByClassName("son")[0];
        console.log(son.offsetLeft);
        console.log(son.offsetTop);
    </script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
请解释分析下面这段程序:%%%无序充电投标 clear clc load data_disorder Pch=[Pch_CS1_disorder;Pch_CS2_disorder;Pch_CS3_disorder;Pch_CS4_disorder];%充电站充电功率 %市场出清问题 Link=zeros(24,96);%时段换算矩阵(日前1h换算为实时15min) for i=1:24 Link(i,4*i-3:4*i)=1; end Loadcurve=[0.955391944564747,0.978345604157644,1,0.995019488956258,0.972932005197055,0.970333477695972,0.930489389346037,0.890428757037679,0.902771762667822,0.941966219142486,0.911000433087917,0.862061498484192,0.840190558683413,0.831095712429623,0.756604590731919,0.671719359029883,0.611520138588133,0.582936336076224,0.572542226071893,0.574707665656128,0.587267215244695,0.644218276310091,0.755521870939801,0.884798614118666]; Loadcurve=Loadcurve*Link;%换成96个时段 PL_base=[5.704;5.705;5.631;6.518;4.890;5.705;5.847]*1000;%负荷分布 PL=PL_base*Loadcurve;%基础负荷(负荷曲线从08:00开始算起,即第9个时段) Pf=sdpvar(7,96);%馈线功率 Pf(1,:)=PL(1,:)+Pch(1,:);Pf(2,:)=PL(2,:);Pf(3,:)=PL(3,:);Pf(4,:)=PL(4,:)+Pch(2,:);Pf(5,:)=PL(5,:)+Pch(3,:);Pf(6,:)=PL(6,:);Pf(7,:)=PL(7,:)+Pch(4,:);%馈线功率组成 Pg=sdpvar(10,96);%发电商分段电量 Pg_step=1000*[20,5,3,2,2,2,2,2,2,inf]';%报价区间 Price_DSO=[3:12]'*0.1;%分段电价 Obj=0.25*sum(sum((Price_DSO*ones(1,96)).*Pg));%目标为用电费用最小 Constraint=[0<=Pg<=Pg_step*ones(1,96),sum(Pg)==sum(Pf)];%约束条件 optimize(Constraint,Obj);%求解线性规划问题 Pg=double(Pg);%发电机功率 Pf=double(Pf);%馈线功率 isPg=(Pg>0);%为了计算出清电价,计算发电机分段选择情况 DLMP=sum(isPg)/10+0.2;%出清电价计算 %绘图 figure(1)%节点边际电价 stairs(DLMP); xlabel 时间 ylabel 电价(元/kWh) ylim([0.3,1.3]) figure(2)%负荷曲线 hold on plot(sum(PL)/1000); plot(sum(Pf)/1000,'r.-'); xlabel 时间 ylabel 负荷(MW) legend('基础负荷','无序充电负荷') Cost=sum(sum(Pch).*DLMP);%总用电费用 result_disorder.Cost=Cost;result_disorder.DLMP=DLMP;result_disorder.Pf=Pf;result_disorder.Pg=Pg;%结果保存 save('result_disorder','result_disorder');
06-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值