使用jQuery的大型HTML、换行符和.HTML()方法
我必须使用使用jQuery的大型HTML、换行符和.HTML()方法,jquery,standards,readability,Jquery,Standards,Readability,我必须使用.HTML()方法在DIV中动态加载以下HTML <div class="box-gerenciamento-versoes-variacoes"> <div class="detalhes-versao"> <p><span>Cor</span> do produto:</p> <img src="/admin/imagens/cores/preto-amarelo.png" hei
.HTML()
方法在DIV中动态加载以下HTML
<div class="box-gerenciamento-versoes-variacoes">
<div class="detalhes-versao">
<p><span>Cor</span> do produto:</p> <img src="/admin/imagens/cores/preto-amarelo.png" height="18" width="18" title="Preto e amarelo" alt="" /> <span class="nome-cor">Preto e amarelo</span>
</div>
<div class="box-enviar-fotos">
<input type="button" class="botao-enviar-fotos" value="" /> 0 fotos enviadas
</div>
<div class="div_clear"></div>
<div class="etiquetas-tamanho-estoque">
<p class="etiqueta-tamanho">Tamanho:</p>
<p class="etiqueta-estoque">Estoque:</p>
</div>
<ul class="gerenciamento-tamanho">
<li>
PP
<input type="text" />
</li>
<li>
P
<input type="text" />
</li>
<li>
M
<input type="text" />
</li>
<li>
G
<input type="text" />
</li>
</ul>
<div class="div_clear"></div>
</div>
生产公司:Preto e amarelo
0 fotos enviadas
塔曼霍:
estoque:
-
聚丙烯
-
P
-
M
-
G
如您所见,内容并不小,而且.html()
方法不允许换行,因此要加载此内容,我必须删除所有换行符,但这样做代码会很难看,这会给应用程序维护带来困难
如何使用jQuery
.HTML()
方法加载HTML的大部分内容,同时保持良好的可读性?为什么需要使用.HTML()
进行加载?例如,我会将此HTML放在一个隐藏的DIV(style=“display:none”
)中,并使用.show()
。@sp00m,我不能这样做,因为我不知道用户将创建多少个框。他可以创建1、3、8或任何其他数量,因此Javascript将动态创建它们。无论如何,谢谢你的提示!
alert("Just put a backslash\
at the end of your lines\
to allow line breaks\
in JavaScript");
var newHtml = $('.box-gerenciamento-versoes-variacoes').html().replace(/(\r\n|\n|\r)/gm,"");
$('.box-gerenciamento-versoes-variacoes').empty().html(newHtml);