Can someone describe and a high level (with detail ofcourse) how one goes about designing a html editor preview feature?

有人可以描述和高级别(详细的课程)如何设计html编辑器预览功能?

(like on this site)

(比如在这个网站上)

What do you have to do really?

你真的要做什么?

1 个解决方案

#1


5

Well, a very simple one might just assign the user's input to the be the HTML of a div. Using jQuery, this would look something like this:

好吧,一个非常简单的可能只是将用户的输入分配给div的HTML。使用jQuery,这看起来像这样:

<textarea id="userInput"></textarea><br>
<div id="previewDiv"></div>

<script>
$(document).ready(function(){
   // Whenever the user input changes, update the preview
   $("#userInput").change(function(){
      $("#previewDiv").html($("#userInput").val());
   }
}
</script>

If you aren't using jQuery, you can investigate the innerHTML property, that is what you would assign to do your preview.

如果您不使用jQuery,则可以调查innerHTML属性,即您为预览分配的属性。

Note that you may want to do some filtering of the user's input; serving arbitrary HTML from your site would allow XSS (cross site scripting) against your domain. Note that writing an effective filter can be very difficult, and a good one (like the one used by stackoverflow) will almost certainly be based on a white-list.

请注意,您可能希望对用户的输入进行一些过滤;从您的站点提供任意HTML将允许针对您的域的XSS(跨站点脚本)。请注意,编写有效的过滤器可能非常困难,并且一个好的过滤器(如stackoverflow使用的过滤器)几乎肯定会基于白名单。

更多相关文章

  1. 下拉列表中的Prestashop过滤器不起作用
  2. 使用jackson json将属性添加到json字符串
  3. React组件的属性PropTypes
  4. Javascript XML DOM将属性设置为特定元素
  5. 为什么我收到此错误:“未捕获的TypeError:无法读取未定义的属性'标
  6. 打字稿:无法访问类属性[重复]
  7. 创建一个对外界只读的属性,但是我的方法仍然可以设置
  8. Javascript没有返回样式属性[重复]
  9. javascript小技巧&&JavaScript[对象.属性]集锦 [转载了多篇]

随机推荐

  1. Android Studio的Gradle文件方法说明
  2. Windows7下使用Eclipse搭建Cocos2dx+Andr
  3. Android核心入门分析
  4. 获取Android SDK 源代码并在Eclipse中关
  5. Android(安卓)Activity 之 startActivity
  6. Android重温
  7. 腾讯Android面经
  8. Android中对同一个TextView设置不同字体
  9. 用 Golang 开发 Android 应用(六)—— Came
  10. 【10.0.1】ArcGIS Runtime for Android之