嗨stackoverflow'ers。我想創建一個像jQuery文本解析器。我想要的是創建一個函數,以傳遞一個字符串並將其轉換。jQuery文本解析器
比方說,我有以下HTML代碼一個div:
<div class="item">
[styled] //The "command" in order to process. If not, return false;
[code1]Text1[/code1]
Text2
[code3]Text3[/code3]
[/styled]
</div>
我想這樣做jQuery的
$(".item").html(my_decode($(this).html());
求變 '的div.item' innerHTML來
<div class="item">
<span class="styled">
<span class="code1">Text1</span>
Text2
<span class="code3">Text3</span>
</span>
</div>
正如你所看到的,它檢查[樣式],如果它存在,創建一個<span>
與clas s「風格」。和對方[]一起,創建一個帶有內容類的`<span>
。
[a]1[/a] [2]a[/2] => <span class="a">1</span> <span class="2">a</span>
謝謝!
究竟是問題還是問題?你正在創建的功能在哪裏? – Borgtex 2012-08-01 19:57:06
@Borgtex有一個,從另一個網站:http://jsfiddle.net/Vbtrq/ – Luis 2012-08-01 20:00:22