用jQuery编写HTML

用jQuery编写HTML,jquery,html,Jquery,Html,我不熟悉jQuery。我想使用jQuery编写以下HTML(以及类)。我该怎么做 <div class="phnbr"> <div class="phtext">hi how are you, <a target="_blank" href="http://www.xyz.com">click here.</a> </div> </div> 你好, 好吧,你可以直接使用 $(document.body).appe

我不熟悉jQuery。我想使用jQuery编写以下HTML(以及类)。我该怎么做

<div class="phnbr">
  <div class="phtext">hi how are you, <a target="_blank" href="http://www.xyz.com">click here.</a>
  </div>
</div>

你好,
好吧,你可以直接使用

$(document.body).append('你好');
$('').addClass('phnbr').append($('').addClass('phtext').append('hi how you')).append($('').attr({target:'u blank',href:'http://www.xyc.com'}).text('单击此处');
$('\
嗨,你好吗\
\
'); // 干得好!

为什么要在jQuery中执行此操作?这不是表示jQuery imho的最佳方式;)@NKCSS,这个比你的解决方案更快。此外,不需要长链语句。此外,还向初学者展示了JQuery的强大功能。etc etcI喜欢这个答案,因为它非常可读HTML结构。在我看来,为每个标记创建对象并使用
append
appendTo
已经与5个以上的标记混淆了。
$(document.body).append('<div class="phnbr"><div class="phtext">hi how are you, <a target="_blank" href="http://www.xyz.com">click here.</a></div></div>');
$('<div>').addClass('phnbr').append($('<div>').addClass('phtext').append('hi how are you, ').append($('<a>').attr({ target: '_blank', href: 'http://www.xyc.com'}).text('click here.')));
$('<div class="phnbr"> \
  <div class="phtext">hi how are you, <a target="_blank" href="http://www.xyz.com">click here.</a> \
  </div> \
</div>'); // bang done!