js操作注意事项

时间:2023-01-10 09:32:24

1、函数赋值给变量时,不能加括号

function fun()

{

  ...

}

var str=fun;

2、js创建构造函数和调用对象,对象内不能用var 变量,只能用this

function fun()
{
    
    this.name="aaa";
    this.age=20;
}
var str=new fun();
document.write(str.name);

3、this  :  谁用了this表示调用当前对象

4、ajax把异表改成同步  async: false, 默认为true 如果为false此参数会以先后顺序执行

 $.ajax({
        async: false,
        type : "GET",
        url : 'tet.php',

        cahce:false,
        complete: function(msg){
            alert('complete');
        },
        success : function(data) {
            alert('success');
            temp=data;
        }
    });
    alert(temp+'   end');
}