簡體   English   中英

使用jQuery在TD中查找div

[英]Find div in td using jquery

我正在嘗試從15 td列獲取div並將div的寬度設置為300px。

我有表摘要來識別該表。 怎么設置寬度?

<table  summary="Copy and Design RFP">
....
...
/* column15*/
<td class="ms-vb2">
    <div dir="">1/9/14 - 1st draft sent</div>
</td>

到目前為止,我寫了

 $(document).ready(function () {
        if (window.location.href.indexOf("dept/mkt/Lists/Request for Projects/Active Projects.aspx") > -1) {
            $('table[summary="Copy and Design RFP"] tr td:nth-child(15)').each(function() {
                var id = $(this).find('div'); // This is not working
            });
        }
    });

使用第nth-child選擇器:

$('table[summary="Copy and Design RFP"] td:nth-child(15) div').css('width', '300px');

我創建此解決方案:

js

var i = 1;
$("table tr").children().each(function(){
    if(i==15){
     var div = $(this).find("div");
     $(div).attr("style","height:300px;");
    }
    i++;
});

小提琴

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM