Re: [問題] javascript動態生成button
※ 引述《PsMonkey (痞子軍團團長)》之銘言:
: 打廣告順便問問題
: 原 po 可參考
: http://pt2wiki.twbbs.org/Wiki.jsp?page=JS_AddDelElementInOnePage
: 我想問的是
: 用這種方法產生 radio
: 在 IE(還是 Fx 有點忘了)下會沒辦法點選
: 不知道有沒有人可以指點一二 Orz
IE 6.0以下版本適用
http://boogie.javaeye.com/blog/26917
http://blog.roodo.com/rocksaying/archives/1848520.html
其實這兩篇是一樣的作法...
────────────────────────────────
話說說到創立元素的話,我會比較喜歡用底下這個。
function elem(name, attrs, style, text,eventstr) {
var e = document.createElement(name);
if (attrs) {
for (key in attrs) {
if (key == 'class')
e.className = attrs[key];
else if (key == 'id')
e.id = attrs[key];
else
e.setAttribute(key, attrs[key]);
}
}
if (style) for (key in style) e.style[key] = style[key];
if (text) e.appendChild(document.createTextNode(text));
if (eventstr) for (key in eventstr)
e.setAttribute(key, new Function(eventstr[key]));
//修正錯誤 21:12
return e;
}
它的使用範例大概就像
var em=elem('select',{name:'cc'+num,id:'cc'+num},'','','');
通用性廣...
────────────────────────────────
這網頁有一些對dom操作的技巧,
http://www-128.ibm.com/developerworks/tw/library/x-matters41.html
也是上述function的原出處。(event是後來自己加上去的。:P)
--
String temp="relax"; | Life just like programing
while(buringlife) String.forgot(temp); | to be right or wrong
while(sleeping) brain.setMemoryOut(); | need not to say
stack.push(life.running); | the complier will
stack.push(scouting.buck()); | answer your life
stack.push(bowling.practice()); | Bone everything
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.134.27.68
※ 編輯: TonyQ 來自: 220.134.27.68 (01/20 21:07)
推
01/20 22:30, , 1F
01/20 22:30, 1F
推
01/21 10:40, , 2F
01/21 10:40, 2F
推
01/21 12:48, , 3F
01/21 12:48, 3F
推
01/21 17:36, , 4F
01/21 17:36, 4F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 4 之 4 篇):