javascript si DOM
Ultima postare: dec 18 2009 23:05, Inițiat de
florin_buda
, feb 13 2008 18:30
·
0
#1
Publicat: 13 februarie 2008 - 18:30
stie cineva de ce functia urmatoare merge in Firefox si nu merge in Internet Explorer ?
function add_a_tr(elem1, elem2, elem3) { var theTr = document.createElement("tr"); var theTd1 = document.createElement("td"); var theTd1Text = document.createTextNode(elem1); var theTd2 = document.createElement("td"); var theTd2Text = document.createTextNode(elem2); var theTd3 = document.createElement("td"); var theTd3Text = document.createTextNode(elem3); theTd1.appendChild(theTd1Text); theTd2.appendChild(theTd2Text); theTd3.appendChild(theTd3Text); theTr.appendChild(theTd1); theTr.appendChild(theTd2); theTr.appendChild(theTd3); document.getElementById('test_table').appendChild(theTr); } in IE pur si simplu nu face nimic |
#2
Publicat: 13 februarie 2008 - 18:47
pentru ca microsoft are o alta viziune despre DOM, incompatibila cu standardele W3C (a carui microsoft e defapt membru, heh).
ti-as recomanda sa folosesti o biblioteca care abstractizeaza diferentele dintre browsere (exista si altele in afara de cele ale mozilla sau microsoft). poti folosi prototype, caci cu el ma mai pricep eu cat de cat, in caz ca ai ajutor |
#6
Publicat: 14 februarie 2008 - 18:05
exemple triviale gasesti pe pagina oficiala. iti ia maxim cateva ore sa te prinzi de majoratatea functionalitatilor. functia ta se poate rescrie asa:
function add_a_tr(elem1, elem2, elem3) { var theTr = new Element('tr'); theTr.insert(new Element('td').update(elem1)); theTr.insert(new Element('td').update(elem2)); theTr.insert(new Element('td').update(elem3)); $('test_table').insert(theTr); } |
#9
Publicat: 15 februarie 2008 - 17:21
uite asta am facut :
<script src="prototype.js"></script> <script> function add_a_tr(elem1, elem2, elem3) { var theTr = new Element('tr'); theTr.insert(new Element('td').update(elem1)); theTr.insert(new Element('td').update(elem2)); theTr.insert(new Element('td').update(elem3)); $('the_table_id').insert(theTr); } </script> <button onclick='java script:add_a_tr("a", "b", "c");'>Test</BUTTON> <table id="the_table_id" border='1'> <tr> <td>un td</td> </tr> </table> in Mozilla merge Ok, in IE nici eroare nici macar o reactie |
#11
Publicat: 15 februarie 2008 - 18:00
deci in primul rand, ce ai tu nici nu e html. as sugera sa incepi sa inveti html mai intai, cum trebuie, ca la carte, nu dupa ureche.
uite aici cod html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script src="lib/prototype/prototype-1.6.0.2.js" type="text/javascript"> </script> <script type="text/javascript"> //<![CDATA[ function add_a_tr(elem1, elem2, elem3) { var theTr = new Element('tr'); theTr.insert(new Element('td').update(elem1)); theTr.insert(new Element('td').update(elem2)); theTr.insert(new Element('td').update(elem3)); $('the_table_id').insert(theTr); } //]]> </script> <title></title> </head> <body> <input type="button" onclick="java script:add_a_tr('a', 'b', 'c');" value="Test"> <table id="the_table_id" border='1'> </table> </body> </html>cu IE6 nu am putut testa pentru ca la mine apare o eroare si se opreste definitiv. altii mi-au raportat ca nu functioneaza - fara sa returneze nicio eroare javascript. concluzie: e imposibil sa repari un script js cu produse microfost. solutie: -. rog cine poate sa testeze/repare codul LE: forumul modifica automat din "javascript" in "java script" in atributul onclick Editat de OriginalCopy, 15 februarie 2008 - 18:03. |
#16
Publicat: 17 februarie 2008 - 19:51
un exemplu derivat din cel facut de OriginalCopy:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> </script> <script type="text/javascript"> function add_a_tr(elem1, elem2, elem3) { var objTblBod = document.getElementById("tbl").tBodies[0]; var objChildTr = document.createElement("tr") var objChildTdA = document.createElement("td") var objChildTdB = document.createElement("td") var objChildTdC = document.createElement("td") var txtA = document.createTextNode(elem1) var txtB = document.createTextNode(elem2) var txtC = document.createTextNode(elem3) objChildTdA.appendChild(txtA) objChildTdB.appendChild(txtB) objChildTdC.appendChild(txtC) objChildTr.appendChild(objChildTdA) objChildTr.appendChild(objChildTdB) objChildTr.appendChild(objChildTdC) objTblBod.appendChild(objChildTr); } </script> <title></title> </head> <body> <input type="button" onclick="java script:add_a_tr('a', 'b', 'c')" value="Test"> <table id="tbl" border='1' width="100"> </table> </body> </html> nu foloseste prototype si nu are cel mai bun mod de a lua id-ul body-ului, dar nu am acum chef sa caut alternative. merge si pe ff si pe ie |
#18
Publicat: 17 februarie 2008 - 21:52
ai inlocuit "java script" cu "javascript" ?
edit: ai dreptate, il facusem sa mearga pe amandoua dupa care l-am curatat ... se pare ca am sters mai mult decat trebuie, revin edit2: nu vrea daca nu are tr, daca-i adaugi un <tr><td>....</td></tr> o sa mearga. nu mai are sens sa imbunatatesc solutia cat timp ai o varianta mai buna un post mai jos. Editat de zuppy, 17 februarie 2008 - 22:06. |
Anunturi
Bun venit pe Forumul Softpedia!
▶ Utilizatori activi: 1
0 membri, 1 vizitatori, 0 utilizatori anonimi