代码之家  ›  专栏  ›  技术社区  ›  brendan

如何将html从textarea传递到jQuery?

  •  1
  • brendan  · 技术社区  · 14 年前

    <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="button" value="Parse It" onclick="ParseIt();" />
    </body>
    </html>
    

    也尝试过此功能,但运气不佳:

    <script type="text/javascript">
        function ParseIt() {
            alert('parsing');
            $($("#html").val()).find('style').each(function () {
                alert('found style');
                alert($(this).text());
            });
        }
    </script>
    
    1 回复  |  直到 14 年前
        1
  •  4
  •   BBonifield    14 年前

    下面的小玩意可能对你更好。

    $( $("#html").val() ).find('style').each(function(){
      // do stuff
    });