Как добавить в элемент текстовый узел
<html> <head> <title></title> <script type="text/javascript"> function func1 (Id, tag, count, message1, message2, message3) { if (document.getElementById (Id).childNodes[3]) { while (document.getElementById (Id).childNodes[3]) { document.getElementById (Id).removeChild (document.getElementById (Id).childNodes[3]) } } else { for (i = 1; i <= count; i++) { var gotElem = document.getElementById (Id); var newElem = document.createElement (tag); newElem.appendChild (document.createTextNode ('message' + i)); gotElem.appendChild (newElem); } } } </script> </head> <body> <div id="head" onclick="func1('head','p', 3, 'example1','example2','example3')"> <h3>Head</h3> </div> </body> </html> вопрос: как сделать, чтобы вместо message1,message2,message3 выводило exapmple1,example2,example3 ? |
Цитата:
<!DOCTYPE html> <html> <head> <!-- <script src="http://code.jquery.com/jquery-latest.js"></script> <link rel="stylesheet" type="text/css" href="tmp.css" /> --> <style type="text/css"> </style> <script type="text/javascript"> function func1 (Id, tag, arr) { if (document.getElementById (Id).childNodes[3]) { while (document.getElementById (Id).childNodes[3]) { document.getElementById (Id).removeChild (document.getElementById (Id).childNodes[3]) } } else { for (var i = 0; i <arr.length; i++) { var gotElem = document.getElementById (Id); var newElem = document.createElement (tag); newElem.appendChild (document.createTextNode (arr[i])); gotElem.appendChild (newElem); } } } </script> </head> <body> <div id="head" onclick="func1('head','p', ['example1','example2','example3'])"> <h3>Head</h3> </div> </body> </html> |
ksa,
Гы - не поспел за Вами ---------------------------- Тады авторским способом: <html> <head> <title></title> <script type="text/javascript"> function func1 (Id, tag, count,message1, message2, message3) { if (document.getElementById (Id).childNodes[3]) { while (document.getElementById (Id).childNodes[3]) { document.getElementById (Id).removeChild (document.getElementById (Id).childNodes[3]) } } else { for (i = 1; i <= count; i++) { var gotElem = document.getElementById (Id); var newElem = document.createElement (tag); newElem.appendChild (document.createTextNode (eval('message'+i))); gotElem.appendChild (newElem); } } } </script> </head> <body> <div id="head" onclick="func1('head','p', 3, 'example1','example2','example3')"> <h3>Head</h3> </div> </body> </html> |
Ваш метод даже больше подходит для моих целей :)
а для чего надо было вставлять эти строки <!-- 05 <script src="http://code.jquery.com/jquery-latest.js"></script> 06 <link rel="stylesheet" type="text/css" href="tmp.css" /> 07 --> ? |
teles,
Эт заготовка универсальной страницы ответов |
Цитата:
- Ты у меня уже пятый... (с) к/ф "В бой идут одни старики" |
Часовой пояс GMT +3, время: 12:16. |