Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript使用表的宽度筛选HTML内容_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript使用表的宽度筛选HTML内容

Javascript使用表的宽度筛选HTML内容,javascript,jquery,html,css,Javascript,Jquery,Html,Css,因此,我得到了一组动态生成的表,它们不可能从原始位置更改,我的问题是:使用JavaScript或任何客户端语言,我可以根据我要查找的宽度为154的表进行过滤吗 <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="154" class="themesdivider"> <img src="/static

因此,我得到了一组动态生成的表,它们不可能从原始位置更改,我的问题是:使用JavaScript或任何客户端语言,我可以根据我要查找的宽度为154的表进行过滤吗

<table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td width="154" class="themesdivider">
            <img src="/static/images/all/spacer.gif" alt="" width="154" height="1" border="0">
        </td>
        <td width="9">
            <img src="/static/images/all/spacer.gif" alt="" width="9" height="1" border="0">
        </td>
        <td width="154" class="themesdivider">
            <img src="/static/images/all/spacer.gif" alt="" width="154" height="1" border="0">
        </td>
        <td width="9">
            <img src="/static/images/all/spacer.gif" alt="" width="9" height="1" border="0">
        </td>
        <td width="154" class="themesdivider">
            <img src="/static/images/all/spacer.gif" alt="" width="154" height="1" border="0">
        </td>
    </tr>
    <tr>
        <td colspan="5">
            <img src="/static/images/all/spacer.gif" alt="" width="10" height="2" border="0">
        </td>
    </tr>
    <tr>
        <td width="154" valign="top" align="left"><a href="/nf/Book/BookDisplay/0,,9780241957110,00.html" target='_top'>
    <img src='/static/covers/all/0/1/9780241957110L.jpg' alt='This Is A Book' width=105 border=0></a>
            <br>
            <img src='/static/images/all/spacer.gif' alt='' width=1 height=8>
            <br> <a href='/nf/Book/BookDisplay/0,,9780241957110,00.html' target='_top' class=themebooktitle><font color=>This Is A Book</font></a>
            <br>
            <img src='/static/images/all/spacer.gif' alt='' width='1' height='5' border='0'>
            <br> <a href='/nf/Author/AuthorPage/0,,0_1000081296,00.html?sym=BIO' target='_top' class=themeauthor><font color=>Demetri Martin</font></a>
            <br>
            <img src='/static/images/all/spacer.gif' alt='' width='1' height='5' border='0'>
            <br> <a href="/nf/Book/BookDisplay/0,,9780241957110,00.html" target='_top' class='thememore' onmouseover='javascript:document.images.a9780241957110.src="/static/images/all/more_arrow1.gif";' onmouseout='javascript:document.images.a9780241957110.src="/static/images/all/more_arrow.gif";'><img src='/static/images/all/more_arrow.gif' alt='' width=18 height=8 border=0 name='a9780241957110'><font color=>Read more...</font></a>
            <br>
            <img src='/static/images/all/spacer.gif' alt='' width='1' height='5' border='0'>
            <br> <span class='themebookprice'><font color=>&#163;9.99</font></span>
            <br>
            <img src='/static/images/all/spacer.gif' alt='' width='1' height='5' border='0'>
            <br> <a href="/nf/Ecommerce/ShoppingCartChange?item=9780241957110" class=themeaddbasket><img src='/static/images/uk/addto_basket.gif' alt=''><img src='/static/images/all/spacer.gif' alt='' width='5' height='1'><font color=>Buy now</font></a>
            <br>
            <img src='/static/images/all/spacer.gif' alt='' width='1' height='5' border='0'>
            <br>
            <br>
        </td>
        <td width="9">
            <img src="/static/images/all/spacer.gif" alt="" width="9" height="1" border="0">
        </td>
        <td width="154" valign="top" align="left"><a href="/nf/Book/BookDisplay/0,,9780241951774,00.html" target='_top'>
    <img src='/static/covers/all/4/7/9780241951774L.jpg' alt='A History of the World in 100 Objects' width=105 border=0></a>
            <br>
            <img src='/static/images/all/spacer.gif' alt='' width=1 height=8>
            <br> <a href='/nf/Book/BookDisplay/0,,9780241951774,00.html' target='_top' class=themebooktitle><font color=>A History of the World in 100 Objects</font></a>
            <br>
            <img src='/static/images/all/spacer.gif' alt='' width='1' height='5' border='0'>
            <br> <a href='/nf/Author/AuthorPage/0,,0_1000079074,00.html?sym=BIO' target='_top' class=themeauthor><font color=>Neil MacGregor</font></a>
            <br>
            <img src='/static/images/all/spacer.gif' alt='' width='1' height='5' border='0'>
            <br> <a href="/nf/Book/BookDisplay/0,,9780241951774,00.html" target='_top' class='thememore' onmouseover='javascript:document.images.a9780241951774.src="/static/images/all/more_arrow1.gif";' onmouseout='javascript:document.images.a9780241951774.src="/static/images/all/more_arrow.gif";'><img src='/static/images/all/more_arrow.gif' alt='' width=18 height=8 border=0 name='a9780241951774'><font color=>Read more...</font></a>
            <br>
            <img src='/static/images/all/spacer.gif' alt='' width='1' height='5' border='0'>
            <br> <span class='themebookprice'><font color=>&#163;9.99</font></span>
            <br>
            <img src='/static/images/all/spacer.gif' alt='' width='1' height='5' border='0'>
            <br> <a href="/nf/Ecommerce/ShoppingCartChange?item=9780241951774" class=themeaddbasket><img src='/static/images/uk/addto_basket.gif' alt=''><img src='/static/images/all/spacer.gif' alt='' width='5' height='1'><font color=>Buy now</font></a>
            <br>
            <img src='/static/images/all/spacer.gif' alt='' width='1' height='5' border='0'>
            <br>
            <br>
        </td>
        <td width="9">
            <img src="/static/images/all/spacer.gif" alt="" width="9" height="1" border="0">
        </td>
        <td width="154" valign="top" align="left"><a href="/nf/Book/BookDisplay/0,,9780141033570,00.html" target='_top'>
    <img src='/static/covers/uk/9780141033570L.jpg' alt='Thinking, Fast and Slow' width=105 border=0></a>
            <br>
            <img src='/static/images/all/spacer.gif' alt='' width=1 height=8>
            <br> <a href='/nf/Book/BookDisplay/0,,9780141033570,00.html' target='_top' class=themebooktitle><font color=>Thinking, Fast and Slow</font></a>
            <br>
            <img src='/static/images/all/spacer.gif' alt='' width='1' height='5' border='0'>
            <br> <a href='/nf/Author/AuthorPage/0,,0_1000081748,00.html?sym=BIO' target='_top' class=themeauthor><font color=>Daniel Kahneman</font></a>
            <br>
            <img src='/static/images/all/spacer.gif' alt='' width='1' height='5' border='0'>
            <br> <a href="/nf/Book/BookDisplay/0,,9780141033570,00.html" target='_top' class='thememore' onmouseover='javascript:document.images.a9780141033570.src="/static/images/all/more_arrow1.gif";' onmouseout='javascript:document.images.a9780141033570.src="/static/images/all/more_arrow.gif";'><img src='/static/images/all/more_arrow.gif' alt='' width=18 height=8 border=0 name='a9780141033570'><font color=>Read more...</font></a>
            <br>
            <img src='/static/images/all/spacer.gif' alt='' width='1' height='5' border='0'>
            <br> <span class='themebookprice'><font color=>&#163;8.99</font></span>
            <br>
            <img src='/static/images/all/spacer.gif' alt='' width='1' height='5' border='0'>
            <br> <a href="/nf/Ecommerce/ShoppingCartChange?item=9780141033570" class=themeaddbasket><img src='/static/images/uk/addto_basket.gif' alt=''><img src='/static/images/all/spacer.gif' alt='' width='5' height='1'><font color=>Buy now</font></a>
            <br>
            <img src='/static/images/all/spacer.gif' alt='' width='1' height='5' border='0'>
            <br>
            <br>
        </td>
    </tr>
</table>









"163,;9.99












"163,;9.99












"163,;8.99





您可以使用
过滤器

var $tds = $('table td').filter(function() {
    return $(this).width() == 154;
});
也可以直接检查属性值:

var $tds = $('table td').filter(function() {
    return $(this).attr('width') == '154';
});
甚至使用单个选择器:

$('table td[width="154"]');

我想后两个选项会更可靠,因为不同浏览器的边距/边距不同。

我不理解你问题的过滤部分,你能告诉我们更多细节吗?