Javascript1

HTML控件元素的name属性有什么约束?
1.不能有空格
2.除了下划线外不能有标点符号
3.name必须在括号之内
4.不能以数字开头


document.getElementById("mytext").select();函数显示的效果是用鼠标把一行字用左键拖动选中 一样

getElementByTagName()函数IE不支持

为什么window.status设置了但是不显示?
打开IE7,在“工具—>Internet 选项—>安全—>选中Internet”,点击“自定义级别”,在【脚本】-【允许状

态栏通过脚本更新】中选择“启用”就行了 
  window .status ="我爱你";
     return true ;


var str="Hello World!"
document.write(str.toUpperCase())


Math.max(value1,value2);取最大值
Math.pow(value,10);一个数的十次方
Math.round(value1);四舍五入的值
Math.floor(Math.random()*6)+1; 随机取6以内的数字


如何动态产生js函数?
   var X2 = {}    //my namespace:)
    X2.Eval = function(code) {
        if (!!(window.attachEvent && !window.opera)) {
            //ie
            execScript(code);
        } else {
            //not ie
            window.eval(code);
        }
    }

    var s = 'global';
    function demo3() {
        X2.Eval(" function test() {alert('1');}");
    }
    demo3();
     test();

 

<noscript>,在不支持JavaScript 时,浏览器显示<noscript>和</noscript>中的内容


如何全屏浏览器?
  function fullScreen() {
        this.moveTo(0, 0);
        window.resizeTo(screen.availWidth,screen.availHeight);
    }
js的screen 对象?
screen 屏幕对象 反映了当前用户的屏幕设置。

width 返回屏幕的宽度(像素数)。

height 返回屏幕的高度。

availWidth 返回屏幕的可用宽度(除去了一些不自动隐藏的类似任务栏的东西所占用的宽度)。

availHeight 返回屏幕的可用高度。

colorDepth 返回当前颜色设置所用的位数 - 1:黑白;8:256色;16:增强色;24/32:真彩色

Navigator浏览器的屏幕对象:


英文的Navigator浏览器的屏幕对象?
availHeight:minus permanent or semipermanent user interface features displayed by the operating

system:such as the Taskbar on Windows. 

availWidth:Specifies the width of the screen, in pixels, minus permanent or semipermanent user

interface:features displayed by the operating system, such as the Taskbar on Windows. 

colorDepth:The bit depth of the color palette, if one is in use; otherwise, the value is derived

from screen.pixelDepth. 

height:Display screen height. 

pixelDepth:Display screen color resolution (bits per pixel). 

width:Display screen width.

 


在Firefox下无onpropertychange事件,必须用input事件来替代,方法如下:

<html>
<head>
</head>
<body>
<form>
<div id="msg"></div>
<input id='txt' value="" />
<script>
//当状态改变的时候执行的函数
function handle()
{document.getElementById('msg').innerHTML='输入的文字长度为:'+document.getElementById

('txt').value.length;
}
//firefox下检测状态改变只能用oninput,且需要用addEventListener来注册事件。
if(/msie/i.test(navigator.userAgent))    //ie浏览器
{
第一种方法:document.getElementById('txt').onpropertychange=handle ;
第二种方法document.getElementById('txt').attachEvent('onpropertychange',function(o){
       alert(o.propertyName);----》这个直接获取到o的哪一项改变了
    });
再继续深挖下:
for(var item in o){
            alert(item+":"+o[item]);
        }----------------》你就会发现里面有很多属性

}
else
{//非ie浏览器,比如Firefox
document.getElementById('txt').addEventListener("input",handle,false);
}
</script>
</form>
</body>
</html>

判断是否是IE7?
<script>
(is_ie && /msie 7/.0/i.test(navigator.userAgent));
</script> 

判断是否是IE?
1.<script>
is_opera = /opera/i.test(navigator.userAgent); 
var is_ie = (/msie/i.test(navigator.userAgent) && !is_opera)
alert(is_ie);
</script> 
2.if (document.uniqueID){
ie能识别出名为uniqueID的document对象的专用属性,名为uniqueID,ie是唯一能够识别这个属性的浏览器

判断浏览器类型?
function getOs(){//判断浏览器类型
var OsObject = "";
if(navigator.userAgent.indexOf("MSIE")>0) {
return "MSIE";
}
if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){
return "Firefox";
}
if(isSafari=navigator.userAgent.indexOf("Safari")>0) {
return "Safari";
}
if(isCamino=navigator.userAgent.indexOf("Camino")>0){
return "Camino";
}
if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){
return "Gecko";


什么是addEventListener?
element.addEventListener(type,listener,useCapture)--》element是要绑定函数的对象
type是事件名称,要注意的是"onclick"要改为"click","onblur"要改为"blur",也就是说事件名不要带"on"。
 
listener是绑定的函数了,记住不要跟括号

最后一个参数是个布尔值,表示该事件的响应顺序
userCapture若为true,则浏览器采用Capture,若为false则采用bubbing方式。建议用false

<div id="div_test"> <input type="button" id="btn_test" value="se4.cn技术基地" /> </div>

window.οnlοad=function(){
 document.getElementById("div_test").addEventListener("click",test1,false);
 document.getElementById("btn_test").addEventListener("click",test2,false);
 }
function test1(){
alert("外层div触发")
}
function test2(){
 alert("内层input触发")
 }

如果userCapture是true则test1先触发,如果userCapture是false则test2先触发。

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值