日期:2014-05-16  浏览次数:20342 次

添加属性的方式,write输出转移字符以及函数变量声明等问题
问题1:
//    var tjElement=document.createElement("li");
//    var idAttribute=tjElement.createAttribute("id");
//    idAttribute.value="tj";
//    var nameAttribute=tjElement.createAttribute("name");
//    nameAttribute.value="tianjin";
    tjElement.setAttribute("id","tj");
    tjElement.setAttribute("name","tianjin");
——————————————————
为什么前者不行,先创建属性,再给属性赋值。

问题2:
document.write输出转移字符的问题?

无法输出/n之类的转移字符。

问题3:
js中函数显式声明变量

//cid,cname是未声明的变量,js中会自动声明。
         function viewData(cid,cname){

为什么显式声明则会报错?

问题4:
Dom对象中方法和属性在文档(js的文档和dom文档都没找到)中查阅不到

比如window对象的dialogArguments属性和setData方法?



------解决方案--------------------
1,createAttribute是document的方法,node对象没有,参考:document.createAttribute方法
    var tjElement=document.createElement("li");
    //var idAttribute=tjElement.createAttribute("id");
    var idAttribute=document.createAttribute("id");
    tjElement.setAttributeNode(idAttribute)
    idAttribute.value="tj";
    //var nameAttribute=tjElement.createAttribute("name");
    var nameAttribute=document.createAttribute("name");
    nameAttribute.value="tianjin";
    tjElement.setAttributeNode(nameAttribute)


2,document.write('\n'),输出再pre标签中才有用,其他标签不会换行,要用br标签
document.write('<pre>1\n2\n3</pre>')
document.write('1\n2\n3')


3,人家语法就那样,除非楼主不用js,用就要按照规则

4,不同浏览器DOM对象有不同的属性,但是大部分是相同的,看这个:http://www.w3schools.com/jsref/dom_obj_node.asp