小编blu*_*dtt的帖子

javascript document.createElement或HTML标记

我对编写代码的风格很困惑.我想知道在文档中插入HTML标记的实用有效的方法.

使用Javascript:

document.getElementById('demoId').innerHTML='<div>hello world and <a>click me</a> also</div>';
Run Code Online (Sandbox Code Playgroud)

要么

var itd=document.createElement('div'),
    ita=document.createElement('a'),
    idt=document.createTextNode('hello world');
    iat=document.createTextNode('click me');
    idn=document.createTextNode('also');

    ita.appendChild(iat);
    itd.appendChild(idt);
    itd.appendChild(ita);
    itd.appendChild(idn)

    docuemtn.getElementById('demoId').appendChild(itd);
Run Code Online (Sandbox Code Playgroud)

哪种方法最快最好?

html javascript optimization createelement

22
推荐指数
1
解决办法
3万
查看次数

'hash'url在.htaccess中重写

我想重写http://example.com/articles.html#first-articlehttp://example.com/articles/first-article

有可能重写吗?

我尝试使用以下但不适合我:

RewriteRule ^articles/(.+)$ /articles\.html\#$1
Run Code Online (Sandbox Code Playgroud)

.htaccess mod-rewrite

19
推荐指数
2
解决办法
3万
查看次数

每个浏览器都支持所有unicode吗?

我想通过使用Unicode而不是小图像图标来减少HTTP请求的数量.

我想使用的图标包括✔,►等.

有关所有必需字符的完整列表,请参阅此处

  • 默认情况下,所有浏览器都支持这些字符
  • 如果默认情况下不支持,我可以添加对这些字符的支持吗?
  • 以跨浏览器的方式将这些字符添加到网页需要哪些CSS和HTML?

另外,我正在制作一个使用以下语言的Unicode网站:

?? ?????? ? ??????? ??????? ?? 
Run Code Online (Sandbox Code Playgroud)
  • 是否可以在每个浏览器和每个操作系统上看到这种语言?
  • 如果可以提供此支持,那么需要哪些CSS和HTML代码?
  • 我需要为此包含一个webfont吗?
  • 我可以使用哪些webfonts以及如何以跨浏览器方式添加它们?

html css unicode cross-browser webfonts

11
推荐指数
1
解决办法
5884
查看次数

有没有其他方法可以在javascript中引用grandParent对象

我有以下代码:

var objectParent:{
     child1:{
       test1:function(){},
       test2:function(){}
      },

      child2:{
       demo1:function(){},
       demo2:function(){},
       parent:this  // gives child2
       grandparent: .... // need to reference objectParent here

      }

    }
Run Code Online (Sandbox Code Playgroud)

我们可以使用这个关键字来引用对象,但是对于大对象还是我的意思是父对象的父对象呢?

现在,我使用祖父母:objectParent来引用父对象

有没有其他方式像这个选择器来引用 parentObject?

这些是我的编码是坏的,好的还是更好的?

javascript

3
推荐指数
1
解决办法
1万
查看次数

参考PHP类函数方法

我有一节课:

class demo {

      function newDemo(){
          $v=$this->checkDemo;
          $v('hello'); // not working this reference, or how to do this?
      }

      function checkDemo($a){
          ...
          return $a;
      }
           }
Run Code Online (Sandbox Code Playgroud)

那么,我如何在类中引用checkDemo函数方法呢?

php

3
推荐指数
2
解决办法
3757
查看次数

javascript中的'this'关键字以不同方式返回

为什么this关键字在以下代码中表达不同的值?

var t = {
    a: "a",
    b: {
        c: "c",
        d: function () {
            return this;
        }
    },
    f: function () {
        return this;
    },
    g: this
}

var k = t.f(),
    l = t.g;

alert(k); // returns [object object] i.e 't'
alert(l); // returns [object DOMWindow] i.e 'window'
Run Code Online (Sandbox Code Playgroud)

javascript

2
推荐指数
1
解决办法
127
查看次数

jQuery中的下一个参数是'undefined',为什么?

在下面的代码中jQuery,为什么下一个参数是undefined

JavaScript的:

(function(a,b){
    ....
})(window)
Run Code Online (Sandbox Code Playgroud)

在这里a=window,但是b=undefined,为什么会这样?

javascript jquery

0
推荐指数
2
解决办法
2666
查看次数