2012-03-02 83 views

回答

2

DOMBrew是一個選項http://jsperf.com/jquery-dom-vs-custom-dom/4

var $b = DOMBrew; 

$("#thetable").append($b('tr#row-of-one').append(
    $b('td.red').append(
    $b('ul').append(
     $b('li.lists', 'one'), 
     $b('li', 'two') 
    ) 
), 
    $b('td.blue').append(
    $b('p', 'This is a bunch of text that is right here.') 
), 

    $b('td.orange').append(
    $b('table#smallertable').append(
     $b('thead').append(
     $b('tr').append(
      $b('th', { colspan: 2, text: 'this is small' }) 
     ) 
    ), 
     $b('tbody').append(
     $b('tr').append(
      $b('td', 'Go win.'), 
      $b('td', 'Go fight.') 
     ) 
    ) 
    )  
), 

    $b('td.purple').append($b('#divided', 'Content')) 
).dom()); 
+0

但我還是必須說,這不是一個很好的方式生成HTML。我使用客戶端模板,比如谷歌封閉模板,這對於理解實際的HTML結構是什麼,可以更快更輕鬆地獲得。https://developers.google.com/closure/templates/docs/helloworld_js – 2012-03-02 23:31:26

+0

服務器端的JavaScript支持以及? – anon 2012-03-07 15:22:57

+0

Google Closure模板可以。它可以使用同一模板生成包含JS(客戶機)和Java(服務器)的HTML https://developers.google.com/closure/templates/docs/helloworld_java – 2012-03-07 16:44:57

相關問題