2015-08-13 67 views
0

我會創建字段textarea,當用戶輸入html basic到textarea時,結果可以讀取html。如何閱讀textarea中的HTML?

代碼的基本

<form action=""> 
    Name: 
    <input type="text"> 
    Contents: 
    <textarea name="contents"></textarea> 
</form> 

I型<strong>Hello World</strong>到textarea的,當提交結果的Hello World
這就好比在WordPress的小部件的文本。

回答

0

您想根據用戶輸入動態創建html元素。嘗試使用JQuery!這裏有一個例子:http://jsfiddle.net/ddan/m7jba0uk/1/

HTML:

<form action=""> 
    Name: 
    <input type="text"><br> 
    Contents: 
    <textarea name="contents"></textarea> 
</form> 
<input type='button' onclick='doTheThing()' value='Do the thing'> 
<div id='result'></div> 

JS:

function doTheThing() { 
    $('#result').append($('textarea[name="contents"]').val()); 
} 

嘗試打字<strong>Hello World</strong>

我希望它有助於實現你的想法。