【问题标题】:Jquery not displaying UL or LI tags in htmlJquery 未在 html 中显示 UL 或 LI 标记
【发布时间】:2013-05-14 20:28:02
【问题描述】:

我有一个简单的代码:

//preview copy as it's being typed
$('#copyText').keyup(function(e){
    $('#copyPreview').html($('#copyText').val());
});

当用户输入 html 时 - 他们可以预览保存后的外观。

However certain tags such as <ul> and <li> are not appearing. Other HTML works such as line breaks, bold, tables, even styles... just not lists (so far, from what I see) 

您可以假设它不是 css,正如我检查过的那样。

示例文本:

<b>All models are UL recognized <br><b>Important:</b> <br>
<ul><li>Adjustable range from -73 to 316°C (-100 to 600°F)</li>
<li>Resolution sensitivity of -17.7°C</li>
</ul>   

【问题讨论】:

  • 你能发布一个包含那些不能正常工作的标签的示例字符串吗?我的猜测是这些字符串不是有效的 html。
  • 您可能必须转义 HTML 实体才能将它们显示为文本而不是呈现这些项目。
  • 什么是copytext?文本区域?
  • @PSL - copyText 是一个文本区域。 copyPreview 是一个 div....
  • 检查这里jsfiddle.net/9Khnz 它按预期工作。

标签: jquery html tags


【解决方案1】:

val() 用于

获取匹配元素集中第一个元素的当前值

改为用户html()

$('#copyPreview').html($('#copyText').html())

【讨论】:

  • 什么?这是错误的,html() 没有从 &lt;input&gt;&lt;textarea&gt; 元素中获取“文本”。
  • 这只是向我显示与他们输入的内容相同的信息,而不是预览在浏览器中的外观。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-12-20
  • 1970-01-01
  • 2012-06-28
  • 2015-07-10
  • 2020-08-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多