可能是一个愚蠢的问题,但仍然在这里。我很难将html代码转换为纯文本,以便在textarea表单字段中查看,但div会执行。将html代码转换为纯文本内div或textarea
以下是我发现:
HTML:
<div class="box-checkbox-color">
<input type="checkbox" name="Color:_Green" id="sku0001-green" value="Yes" />
<label for="sku0001-green"></label>
<div style="display:none;" title="#" class="rawHTML-code-insert">This is where I would like to display raw HTML code BUT have it rendered as plain text instead of being read as markup, essentially need it to be presented so it can be copied and pasted</div>
</div>
<div class="box-checkbox-color">
<input type="checkbox" name="Color:_Green2" id="sku0001-green2" value="Yes" />
<label for="sku0001-green2"></label>
<div style="display:none;" title="#" class="rawHTML-code-insert">This is where I would like to display raw HTML code BUT have it rendered as plain text instead of being read as markup, essentially need it to be presented so it can be copied and pasted into a form field to be sent to another .php page</div>
</div>
<ul class="result"></ul>
的Javascript:
$('input[type="checkbox"]').click(function(){
var title = $(this).closest('.box-checkbox-color').find('.rawHTML-code-insert').html();
// If the checkbox is checked, add the item to the ul.
if($(this).attr('checked')){
var html = '<li title="' + title + '">' + title + '</li>';
$('ul.result').append(html);
} else {
// if the checkbox is unchecked, remove the item from the ul.
$('li[title="' + title + '"]').remove();
}
});
我需要这个来完成是显示/生成特定的代码块当用户检查一个特定的复选框时,但我希望代码可以作为代码读取,而不是作为标记读取并执行。要点是提供代码,以便用户可以复制和粘贴它,并修改div名称,ID,值等,如果他们想。当然,每个复选框都会显示不同的代码,并在下面的ul类中一起列出。我提供了一个js小提琴,应该说明我需要什么。
我提供了一个我正在谈论的js fiddle示例。
使用jQuery'的.text()'把代码放到textarea的。 – Barmar
你会如此善良,以显示它在jsfiddle。我知道这是一个屁股,但它会让我妻子感觉更好,哈哈。 – WebEducate