用$(美元符号)替换document.getElementById [英] Replacing document.getElementById with $ (dollar sign)
问题描述
我见过一些框架使用以下内容:
function $(id){return document.getElementById(id); }
然后使用:
$(''something'')。innerHTML ='''blah'';
我只是想把它推到我的网站上,到目前为止这已经保存了大约8KB的javascript(大量的ajax /动态元素)
。我只是
想知道这样做是否有任何浏览器问题?
我已经在IE7,FF2,Safari 3和IE6上进行了测试没有看到任何
的问题。有什么浏览器不能用吗?
谢谢
I''ve seen a few frameworks use the following:
function $(id) { return document.getElementById(id); }
Then to use:
$(''something'').innerHTML = ''blah'';
I''m just trying to roll this out to my site and so far doing this has
saved about 8KB of javascript (lots of ajax/dynamic elements). I just
want to know whether there''s any browser problems with doing this?
I''ve tested it on IE7, FF2, Safari 3 and IE6 and can''t see any
problems. Are there any browsers that this won''t work on?
Thanks
推荐答案
(id) {return document.getElementById(id); }
然后使用:
(id) { return document.getElementById(id); }
Then to use:
(''something'')。innerHTML =''blah' ';
我只是想把它推到我的网站上,到目前为止这已经保存了大约8KB的javascript(很多ajax) /动态元素)。我只是
想知道这样做是否有任何浏览器问题?
我已经在IE7,FF2,Safari 3和IE6上进行了测试没有看到任何
的问题。有什么浏览器不能用吗?
谢谢
(''something'').innerHTML = ''blah'';
I''m just trying to roll this out to my site and so far doing this has
saved about 8KB of javascript (lots of ajax/dynamic elements). I just
want to know whether there''s any browser problems with doing this?
I''ve tested it on IE7, FF2, Safari 3 and IE6 and can''t see any
problems. Are there any browsers that this won''t work on?
Thanks
5月28日上午8:47, Nick< nick.lemou ... @ gmail.comwrote:
On May 28, 8:47 am, Nick <nick.lemou...@gmail.comwrote:
我见过一些框架使用以下内容:
函数
I''ve seen a few frameworks use the following:
function
这篇关于用$(美元符号)替换document.getElementById的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!