从Web表单创建代码片段(易于剪切和粘贴)


Create Code Snippet (easy to cut and paste) from Web Form

我希望非开发人员的工作人员能够在一个表单(日期,时间,价格,描述)中输入文本到4-5个字段,然后在页面底部有一个框,显示自定义HTML代码与他们的答案自动嵌入,所以他们可以剪切和粘贴HTML。

或者,将表单发送到第二个页面,但将其显示为HTML源代码,以便他们可以全选,剪切,然后粘贴到另一个应用程序。

谢谢。

text [form field]
name: [bob]
price: [50]
description: [come to our event]
url for event: [url.com/event-02]
<html>
<p class="name">bob</p>
<p class="price">50</p>
<p class="desc">come to our event</p>
<p class="url">Share the <a href="url.com/event-02">event with your friends</a></p> 
</html>

类似这样,使用val()从用户获取输入:

HTML:

name:<input type="text" id="name" />
<br />
price:<input type="text" id="price"/>
<br />
description:<input type="text" id="description"/>
<br />
url for event:<input type="text" id="url_for_event" />
<br />
<button id="create-html">create html</button>
<div id="result"></div>

JS:

$( "#create-html" ).click(function() {
    var name = '<p class="name">' + $("#name").val() + '</p>';
    var price = '<p class="price">' + $("#price").val() + '</p>';
    var description = '<p class="desc">' + $("#description").val() +'</p>';
    var url_for_event = '<p class="url">Share the <a href="' + $("#url_for_event").val() +'">event with your friends</a></p>';
    $( "#result" ).text(name + price + description + url_for_event);
});

演示:http://jsfiddle.net/cLK7z/2/

尝试让提交按钮触发一个JS函数。

<form action="">
  <!-- your form -->
  <input type="submit" value="Submit" onclick="parseThisCrapIntoHtml(this);return!1" />
</form>

现在,解析成HTML应该相对简单,主要由字符串操作组成。