var res=prompt(‘输入姓名‘,‘MWL‘);
alert(res);
6、scrollTop
滚动距离
var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;
console.log(typeof scrollTop); //number
alert(‘您已经滚动了‘+scrollTop+"px的距离");
7、window.navigator.userAgent
浏览器信息
alert(window.navigator.userAgent);
8、write()
显示信息,但之前的信息会消失
window.onload=function()
{
var btn1=document.getElementById(‘btn1‘);
btn1.onclick=function()
{
document.write(‘asdasd‘);
}
}
9、document.documentElement.clientWidth
可视区
window.onload=function ()
{
var oBtn=document.getElementById(‘btn1‘);
oBtn.onclick=function ()
{
alert(document.documentElement.clientWidth+‘,‘+document.documentElement.clientHeight);
};
};
10、运行输入框中的代码
html:
JS:
window.onload=function ()
{
var oTxt=document.getElementById(‘txt1‘);
var oBtn=document.getElementById(‘btn1‘);
oBtn.onclick=function ()
{
var oNewWin=window.open(‘about:blank‘,‘_blank‘)
oNewWin.document.write(oTxt.value);
};
};
来源: http://www.bubuko.com/infodetail-2415555.html