From right to left: Five iterators

Source: Internet
Author: User

if we want to filter some nodes from left to right, we can use the nodes on hand now, but from right to left, we need to filter these nodes based on their fathers, children, and siblings. After filtering, these nodes used for comparison cannot be discarded, and they can also be used for the next filtering. In this way, there is a proxy relationship. We need some proxies to do this. Of course, a proxy is not required for div. AAA, But Div. AAA is required. In the left-to-right scenario, all the relational selectors we talk about are mainly parent-child siblings and adjacent three types. When encountering descendant selectors, we can convert them to wildcard selectors and tag selectors. From the right to the left, the relationship selector includes five adjacent child-parent and child-brother wildcards. The wildcard character is essentially a child selector with hierarchical relationships.

// Obtain the Union var getparent = function (testee, result, Yess, pid) {While (testee = testee. parentnode) {pid = testee. uniqueid | (testee. uniqueid = Dom. UID ++); If (Yess [pid]) {result = testee} return result;} var iterators = {current: function (nextset) {var set = This, nodes = This. nodes, tagname = This. tagname, filter = This. filter, argS = This. ARGs, result = [], testee, uid; For (VAR I = 0, rI = 0, Node; node = nodes [I ++];) {uid = node. uniqueid | (node. uniqueid = Dom. UID ++); testee = set [uid] | node; If ((! Tagname | tagname === testee. nodename )&&(! Filter | filter. apply (testee, argS) {result [ri ++] = node; nextset [uid] = testee ;}} nextset. nodes = result;}, parent: function (nextset) {var set = This, nodes = This. nodes, tagname = This. tagname, filter = This. filter, argS = This. ARGs, result = [], Yess = {}, testee, uid, PID; For (VAR I = 0, rI = 0, node; node = nodes [I ++];) {uid = node. uniqueid | (node. uniqueid = Dom. UID ++); testee = set [uid] | Node; while (testee = testee. parentnode) & testee. nodetype = 1) {pid = testee. uniqueid | (testee. uniqueid = Dom. UID ++); If (Yess [pid]) {result [ri ++] = node; nextset [uid] = testee; break;} If ((! Tagname | tagname === testee. nodename )&&(! Filter | filter. apply (testee, argS) {Yess [pid] = Result [ri ++] = node; nextset [uid] = testee;} break;} nextset. nodes = result;}, iterators. parents = function (nextset) {var set = This, nodes = This. nodes, tagname = This. tagname, filter = This. filter, argS = This. ARGs, level = This. level, _ level, result = [], testee, uid, PID, Yess ={}; for (VAR I = 0, rI = 0, node; node = nodes [I ++];) {uid = Node. uniqueid | (node. uniqueid = Dom. UID ++); testee = set [uid] | node; while (testee = testee. parentnode) {If (testee. nodetype = 1) {If (level) {_ Level = level; while (_ level -- & (testee = testee. parentnode) {} If (! Testee) {break;} pid = testee. uniqueid | (testee. uniqueid = Dom. UID ++); If (Yess [pid]) {result [ri ++] = node; nextset [uid] = nextset [Yess [pid]. uniqueid]; break;} If ((! Tagname | tagname === testee. nodename )&&(! Filter | filter. apply (testee, argS) {Yess [pid] = Result [ri ++] = node; nextset [uid] = getparent (testee, result, Yess, pid ); break ;}}} nextset. nodes = result;} border: function (nextset) {var set = This, nodes = This. nodes, tagname = This. tagname, filter = This. filter, argS = This. ARGs, result = [], testee, uid; For (VAR I = 0, rI = 0, node; node = nodes [I ++];) {uid = node. uniqueid | (node. unique Id = Dom. UID ++); testee = set [uid] | node; while (testee = testee. previussibling) & testee. nodetype = 1) {If ((! Tagname | tagname === testee. nodename )&&(! Filter | filter. apply (testee, argS) {result [ri ++] = node; nextset [uid] = testee;} break ;}} nextset. nodes = result;}, borders: function (nextset) {var set = This, nodes = This. nodes, tagname = This. tagname, filter = This. filter, argS = This. ARGs, result = [], Yess = {}, testee, uid, PID; For (VAR I = 0, rI = 0, node; node = nodes [I ++];) {uid = node. uniqueid | (node. uniqueid = Dom. UID ++); testee = Se T [uid] | node; while (testee = testee. previussibling) & testee. nodetype = 1) {pid = testee. uniqueid | (testee. uniqueid = Dom. UID ++); If (Yess [pid]) {result [ri ++] = node; nextset [uid] = testee break;} If ((! Tagname | tagname === testee. nodename )&&(! Filter | filter. apply (testee, argS) {Yess [pid] = Result [ri ++] = node; nextset [uid] = testee; break ;}} nextset. nodes = Result ;}}

they have several similarities and are considering whether to generate them dynamically ......

<Br/> <! Doctype HTML> <br/> <pead> <br/> <title> select from right to left: Test style (for Link selector) </title> <br/> <meta http-equiv = "X-UA-compatible" content = "Ie = 8"/> <br/> <SCRIPT src = "dom /lib/queryv41.js "> </SCRIPT> <br/> <style> <br/> span ~ SPAN ~ SPAN {<br/> color: red; <br/>}< br/> </style> </P> <p> <SCRIPT> <br/> window. onload = function () {<br/> var show = function (sets) {<br/> var array = [] <br/> for (var I IN SETS) {<br/> array. push (sets [I]. innerhtml) <br/>}< br/> alert (array) <br/>}< br/> // "Tr ~ Tr ~ TR "<br/> // Div span ~ SPAN <br/> // Div + Div span <br/> // tr + Tr <br/> // var els = Dom. Query ("span ~ SPAN ~ Span "); <br/> // alert (els. length) <br/> // show (ELS) <br/>}< br/> </SCRIPT> </P> <p> </pead> <br/> <body> </P> <p> <Table class = "filament_table" cellspacing = "0" width = "700" rules = "Cols" border = "1"> <br/> <Col class = "gray" width =" 30% "> </COL> <br/> <Col class =" yellow "> </COL> <br/> <thead> <br/> <tr> <br/> <TH> property </Th> <br/> <TH> value </Th> <br/> </tr> <br/> </thead> <br/> <tbody> <br/> <tr> <br/> <TD> display </TD> <br/> <TD> inline-block </TD> <br/> </tr> <br/> <TD> height </TD> <br/> <TD> any value </TD> <br/> </tr> <br/> <TD> float </TD> <br/> <TD> left or right </TD> <br /> </tr> <br/> <TD> position </TD> <br/> <TD> absolute </TD> <br/> </tr> <br/> <TD> width </TD> <br/> <TD> any value </TD> <br/> </tr> <br/> <TD> writing-mode </TD> <br/> <TD> TB-rl </TD> <br/> </tr> <br/> <TD> zoom </TD> <br/> <TD> any value </TD> <br/> </tr> <br/> </tbody> <br/> </table> <br/> <Div id = "parent1" class = "CCC bbb "> <br/> <span> 11111111 </span> <br/> </div> </P> <p> <div> <br/> <span> 54354435 </span> <br/> <Div id = "parent2"> <br/> <SPAN class = "aaa bbb"> aaaaaaaaa </span> <br/> <Span> bbbbbbbbb </span> <br/> <strong> ccccccc </strong> <br/> <span> dddddddd </span> <br/> <div> <br/> <span> 44444444 </span> <br/> </div> <br/> <span ID = "Prev"> 555555555 </span> </P> <p> </body> <br/> </ptml> </P> <p>

RunCode

Use Time cut to replace uid Filtering

Select Div

 
3 3

Descendant

VaR fathers = function () {var querytime = Dom. querytime // new date-0 var nodes = This [0], set = This [1], argS = This [4], filter = This [5], _ set = [], _ nodes = [], I = 0, rI = 0, node, testee; while (testee = set [I]) {node = testee; // node is selected from the candidate set from the beginning to the end, and testee is selected from the elders of the Set element while (testee = testee. parentnode) {If (testee. querytime = querytime) {_ set [ri] = testee; _ nodes [ri ++] = nodes [I]; break;} If (testee. nodename = "Div") {testee. querytime = querytime _ set [ri] = testee; _ nodes [ri ++] = nodes [I]; break ;}} I ++ ;} this [0] = _ nodes; this [1] = _ set; this. length = 3 ;}

Parent-Child

VaR father = function () {var querytime = Dom. querytime; var nodes = This [0], set = This [1], argS = This [4], filter = This [5], _ set = [], _ nodes = [], I = 0, rI = 0, node, testee; while (testee = set [I]) {node = testee; while (testee = testee. parentnode) {If (testee. querytime = querytime) {_ set [ri] = testee; _ nodes [ri ++] = node; break;} If (testee. nodename = "Div") {testee. querytime = querytime _ set [ri] = testee; _ nodes [ri ++] = node;} break;} I ++;} This [0] = _ nodes; this [1] = _ set; this. length = 3 ;}

2011.1.26

VaR border = function (expr, set, flag_xml) {var selector, filter = rage. filter; expr = expr. replace (reg_tag, function ($) {selector =$ == '*'? True: flag_xm? $: $. Touppercase (); Return '';}); For (VAR I = 0, n = set. length; I
VaR parent = function (expr, set, flag_xml) {var selector, filter = rage. filter; expr = expr. replace (reg_tag, function ($) {selector =$ == '*'? True: flag_xm? $: $. Touppercase (); Return '';}); For (VAR I = 0, n = set. length; I
 var borders = function (expr, set, flag_xml) {var selector, filter = rage. filter, _ filter = rage. _ filter, flag_fn = false, old = expr, prop = 'previussibling '; expr = expr. replace (reg_first, function ($) {If (reg_tag.test ($) {selector =$ == '*'? True: flag_xm? $: $. Touppercase () ;}else {selector =$; flag_fn = true;} return '';}); If (expr === old) {Throw old + 'syntax error';} _ filter. call (null, selector, set, prop, flag_fn); expr & filter. call (null, expr, set, true) ;}
 var parents = function (expr, set, flag_xml) {var selector, filter = rage. filter, _ filter = rage. _ filter, flag_fn = false, old = expr, prop = 'parentnode'; expr = expr. replace (reg_first, function ($) {If (reg_tag.test ($) {selector =$ == '*'? True: flag_xm? $: $. Touppercase () ;}else {selector =$; flag_fn = true;} return '';}); If (expr === old) {Throw old + 'syntax error';} _ filter. call (null, selector, set, prop, flag_fn); expr & filter. call (null, expr, set, true) ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.