简体   繁体   English

如何从用户读取文本区域中的数据粘贴并将Jquery代码应用于该文本

[英]How can I read the data paste in text area from user and apply the Jquery code on that text

<html>
<head>
</head>
<body>

<textarea id="area" style="width:100%; height:60px;"></textarea>
<button id="submit">Submit</button>


<script>
$(document).find('h1, h2, h3, h4, h5, h6').each(function() {
if ($(this).parent().prev().is('h1, h2, h3, h4, h5, h6') != true) {
    $(this).parent().before('<p>xxxxxxx</p>');
}
});
</script>
</body>
</html>

From the above code i want to accept a html file from the user in Text area and then on that text how can i perform above jquery code. 从以上代码中,我想在文本区域中接受用户的html文件,然后在该文本上如何执行上述jquery代码。

without user interface ,this code is working. 没有用户界面,此代码有效。 for example 例如

https://jsfiddle.net/Aramil/rebpb5h2/5/ https://jsfiddle.net/Aramil/rebpb5h2/5/

here html page is pasted directly without user interface option. 此处的html页面直接粘贴而没有用户界面选项。

Is it Possible? 可能吗?

can any one help me out,Any Help would be a great help. 任何人都可以帮助我,任何帮助都将是一个很大的帮助。

See this fiddle if it answers your question -- https://jsfiddle.net/rebpb5h2/6/ 如果它回答了您的问题,请参阅此小提琴-https: //jsfiddle.net/rebpb5h2/6/

Summary 摘要

  • The textarea holds the HTML codes to be processed. 文本区域保存要处理的HTML代码。
  • A <div> with id 'changedContentWrapper' holds the result. ID为'changedContentWrapper' <div>保存结果。
  • The <button> with id 'button' triggers the processing. ID为'button'<button>触发处理。

EDIT. 编辑。 I have updated the fiddle, so that you can make changes to the content of the textarea to be processed -- see it here https://jsfiddle.net/rebpb5h2/7/ 我已经更新了小提琴,以便您可以更改要处理的文本区域的内容-在此处查看https://jsfiddle.net/rebpb5h2/7/

FINAL EDIT. 最终编辑。 Has two textareas, one for the 'before' processing, and one for the 'after' processing -- https://jsfiddle.net/rebpb5h2/9/ 有两个文本区域,一个用于``之前''处理,一个用于``之后''处理-https://jsfiddle.net/rebpb5h2/9/

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM