比如我现在已知一个字符串“数学”,怎样才能通过“数学”定位到包含这两个字的标签呢?

解决方案 »

  1.   

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script language="javascript" type="text/javascript">
            function getNode() {         var parentNode = document.all? document.selection.createRange().parentElement():
             window.getSelection().focusNode.parentNode;
             alert(parentNode.tagName);        }        
        </script>
    </head><body>
        <div name="parent">
         <input type="button" value="getNode" onclick="getNode()">
         <span>1234567</span>
        </div>
    </body>
    </html>