0

次の html レンダリングが与えられます。

<fieldset id="fld_Rye">
 <legend>7 Main St.</legend>
<div>
    <table>
        <tr>
        <th class="wideCol"><b><i>Service Description</i></b></th>
        <th class="wideCol"><b><i>Service Name</i></b></th>
        <th class="normalPlusWidth"><b><i>Contact Name</i></b></th>        
    </tr>
    <ItemTemplate>
        <tr class="">
        <td class="servDesc">&nbsp;<b>Plumbing Services</b></td>
                    <td class="servName">&nbsp;<b>Flynnsters's Plumbing</b></td>
                    <td class="servContact">&nbsp;<b>Jim Flynnster</b></td>
        </tr>
    </ItemTemplate>

servDesc のクラスですべての td にアクセスし、それらの幅を配列に取得し、その配列から最大幅を取得して、ページの読み込み時に jquery を使用してそのクラスの css 幅をリセットしようとしています。これらのタグに適したセレクターが見つからないようで、少なくとも 50 のバリエーションを試しました。

私の最近の試み;

 var maxTdWidth;
        var servDescCols = [];
        $("#fld_Rye td#servDesc").each(function () {
            alert("found one");
            servDescCols.push($(this).width());
        });
        maxTdWidth = Math.max.apply(Math, servDescCols);
4

1 に答える 1

0

すべてのtdwithservDescクラスを取得するには、これを試してください

$("td.servDesc").each(function () {
            alert("found one");
            servDescCols.push(this.width());
     });

任意の要素をターゲットにして内部の td を取得する場合は、これを使用します

「table1」は基本要素の ID です

$("#table1").find("td.servDesc").each(function () {
        alert("found one");
        servDescCols.push(this.width());
 });
于 2013-10-20T15:51:30.127 に答える