我对编写代码的风格很困惑.我想知道在文档中插入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)
哪种方法最快最好?
我想重写http://example.com/articles.html#first-article与http://example.com/articles/first-article
有可能重写吗?
我尝试使用以下但不适合我:
RewriteRule ^articles/(.+)$ /articles\.html\#$1
Run Code Online (Sandbox Code Playgroud) 我想通过使用Unicode而不是小图像图标来减少HTTP请求的数量.
我想使用的图标包括✔,►等.
有关所有必需字符的完整列表,请参阅此处
另外,我正在制作一个使用以下语言的Unicode网站:
?? ?????? ? ??????? ??????? ??
Run Code Online (Sandbox Code Playgroud)
我有以下代码:
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?
这些是我的编码是坏的,好的还是更好的?
我有一节课:
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函数方法呢?
为什么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) 在下面的代码中jQuery,为什么下一个参数是undefined
JavaScript的:
(function(a,b){
....
})(window)
Run Code Online (Sandbox Code Playgroud)
在这里a=window,但是b=undefined,为什么会这样?
javascript ×4
html ×2
.htaccess ×1
css ×1
jquery ×1
mod-rewrite ×1
optimization ×1
php ×1
unicode ×1
webfonts ×1