0

我有这种类型的 html :-

<ul>
  <li>Activities<ul>
      <li>Physical1<ul>
          <li>Cricket<ul>
              <li>One Day</li>
            </ul>
          </li>
        </ul>
      </li>
      <li>Test1<ul>
          <li>Test At Abc</li>
        </ul>
      </li>
      <li>Test2<ul>
          <li>Test At Xyz</li>
        </ul>
      </li>
    </ul>
  </li>
</ul>
<br>

这是我加载 xml 文件和 xslt 的完整代码。并使用 xslt 获取 ul li 列表。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

    <title>Untitled Page</title>
    <script>
        var xml = loadXMLDoc("abc.xml");
        var xsl = loadXMLDoc("a.xsl");

        function loadXMLDocActiveX(location) {
            var doc = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
            doc.async = false;
            doc.load(location);
            return doc;
        }

        function loadXMLDocOther(location) {
            xhttp = new XMLHttpRequest();
            xhttp.open("GET", location, false);
            xhttp.send("");
            return xhttp.responseXML;
        }

        function loadXMLDoc(dname) {
            if (window.ActiveXObject) {
                return loadXMLDocActiveX(dname);
            }
            else if (window.XMLHttpRequest) {
                return loadXMLDocOther(dname);
            }
        }

        function transformActiveX(xml, xsl, target, selected) {
            var transform = new ActiveXObject("MSXML2.XSLTemplate");
            transform.stylesheet = xsl;
            var processor = transform.createProcessor();
            processor.input = xml;

            if (selected) {
                processor.addParameter("selected", selected);
            }

            processor.transform();
            target.innerHTML = processor.output;
        }

        function transformOther(xml, xsl, target, selected) {
            var xsltProcessor = new XSLTProcessor();
            xsltProcessor.importStylesheet(xsl);

            if (selected) {
                xsltProcessor.setParameter(null, "selected", selected);
            }

            var resultDocument = xsltProcessor.transformToFragment(xml, document);
            target.innerHTML = "";
            target.appendChild(resultDocument);
        }

        function displayResult() {
            var targetElement = document.getElementById("load");

            // code for IE
            if (window.ActiveXObject) {
                transformActiveX(xml, xsl, targetElement);
            }
            // code for Mozilla, Firefox, Opera, etc.
            else if (document.implementation && 
                     document.implementation.createDocument) {
                transformOther(xml, xsl, targetElement);
            }
        }
    </script>
</head>
<body onload="displayResult()">
    <div id="load">
    </div>
</body>
</html>

我想在单击叶节点时设置单击叶​​节点,其文本设置在我的 <div id="result"/> 例如:-单击One Day其最后一个没有子节点的子节点,然后将其文本复制到div标签中。
它怎么可能......我认为它与jquery函数点击一起工作。
谢谢...

4

2 回答 2

2

听起来你需要修改 HTML,无论如何试试这个:

工作演示

$('li:not(:has(*))').click(function(){
     $('#result').text($(this).text());
});


<div id="result"></div>
于 2013-04-24T12:31:42.900 回答
1

这将选择所有没有孩子的 li。然后只需附加点击事件。(假设有效的 HTML)

$('li:not(:has(*))').click(.....)
于 2013-04-24T12:26:14.810 回答