我有一个文本区域,我正在填充html
代码,供人们从中删除&粘贴。这个textarea使用JQuery和.html()来“填充”。与“人口”从<div>
页面例子在其他地方来:JQuery .html()打印准确的html代码
的div“举办的‘人口’
<div id="populationhold">this is the html to copy</div>
那么‘JQ的魔术’‘点击’按钮,然后填充textarea的
$('#button').click(function(){
updatefunction();
});
和updatefunction是有点像这样:
function updatefunction(){
$('#textarea').html($('#populationhold').val(); });
}
现在如果我尝试像这样的东西来填充:
$('#textarea').html('this is the <br />html to copy');
的html的()将只打印<br>
不<br />
。我试过了(用我的方式逃避<br \/>
,但那不行。建议请,因为我必须“产生”干净的XHTML代码不仅仅是HTML4代码
下一位是概率只是相同,但有点更复杂的 - 因此上面的领导到这个
为“用户”我的网站,你将能够从代码示例添加/删除位:
<div id="populationhold">
<div class="codebit1">this is the <br />html to copy</div>
\n<br/>\
<div class="codebit2">this is more <br />html to copy</div>
</div>
$('#button').click(function(){
$('#textarea').html($('#populationhold').val();
});
填充textarea的是罚款和工作,所以“90%”的删除。这是这样的:
$('#deletebutton').click(function(){
$('.codebit1').remove();
// This removes .codebit1 from #populationhold and runs the update to ummm update the textarea with the update function
// Note: remove() is OK in this case as #codebit1 is totally dynamically created
updatefunction();
});
这里的问题是好的我可以删除/删除需要删除的位 - 因此“90%”,但我怎样才能摆脱“现在的孤儿”\n<br/>\n
用于分隔#textarea中的2个div 。好吧,我可以在没有\n<br/>\n
的情况下做到这一点,但它会让代码复制到“不整齐”的眼睛上,这就是为什么\n<br/>\n
在那里的原因--也确保当代码被真正复制时,用户会得到合理的布局。
您是否使用了正确的文档类型? – 2011-02-11 11:59:20
@Timo我正要问同样的事情...... – 2011-02-11 12:03:28