How can I pass html from textarea into jQuery?
I have the following html snippet. I am trying to let a user enter some html into the textarea, then I will parse out their style block and do some things with their styles. How can I pass the html string from the #html textarea into jQuery so I can parse it?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="script/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
function ParseIt() {
alert($("#html").val());
$("style", $("#html")).each(function(){ alert($(this).text());});
}
</script>
</head>
<body>
<textarea id="html" name="html" class="email_body " rows="25" cols="100"></textarea>
<br />
<input type="butt开发者_运维问答on" value="Parse It" onclick="ParseIt();" />
</body>
</html>
Have also tried this function with no luck:
<script type="text/javascript">
function ParseIt() {
alert('parsing');
$($("#html").val()).find('style').each(function () {
alert('found style');
alert($(this).text());
});
}
</script>
The snippit below might be better for ya.
$( $("#html").val() ).find('style').each(function(){
// do stuff
});
精彩评论