XPath不能用在js1.6上??????

  XPath Selectors

XML Path Language (XPath) is a type of language for identifying different elements or their values within XML documents, similar to the way CSS identifies elements in HTML documents. The jQuery library supports a basic set of XPath selectors that we can use alongside CSS selectors, if we so desire. And with jQuery, both XPath and CSS selectors can be used regardless of the document type.

When it comes to attribute selectors, jQuery uses the XPath convention of identifying attributes by prefixing them with the @ symbol inside square brackets, rather than the less-flexible CSS equivalent. For example, to select all links that have a title attribute, we would write the following:

$('a[@title]')

This XPath syntax allows for another use of square brackets, without the @, to designate an element that is contained within another element. We can, for example, get all div elements that contain an ol element with the following selector expression:

$('div[ol]')

下面是用xpath选择器做的实验,但是发现xpath不能用在js1.6版本上,不知道怎么个情况,希望知道的人给以解答

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

    <base href="<%=basePath%>">

    <script src="js/jquery.js" type="text/javascript"></script>

    <!--

    <script src="http://code.jquery.com/jquery-latest.js"></script>

     -->

     <style type="text/css">

        a{

           color: #00f; /* make plain links blue */

       }

       a.mailto{

           color: #f00; /* make email links red */

       }

       a.pdflink{

           color: #090; /* make PDF links green */

       }

       a.mysite{

           text-decoration: none; /* remove internal link underline */

           border-bottom: 1px dotted #00f;

       }

     </style>

     <script type="text/javascript">

        $(document).ready(function() {

           /*用Xpath在js1.6上是不行的(自己的实验,不知道怎么个情况)

           $('a[@href^="mailto:"]').addClass('mailto');

           $('a[@href$=".pdf"]').addClass('pdflink');

           $('a[@href*="mysite.com"]').addClass('mysite');

           */

           $('a[href$=".pdf"]').addClass('pdflink');

           $("a[href^='mailto:']").addClass("mailto");

           $('a[href*="mysite.com"]').addClass('mysite');

       });

     </script>

  </head>

 

  <body>

    <a href="http://www.mysite.com/asyoulikeit/">As You Like It</a>

     <a href="hamlet.pdf">Hamlet</a>

     <a href="mailto:[email protected]">email</a>

  </body>

</html>

你可能感兴趣的:(XPath不能用在js1.6上??????)