Я хочу получить значение содержимого td таблицы при нажатии на некоторый тип ввода, который находится внутри другого тд этой же таблицы.

Скажем так:

<table width="100%" border="1">
        <thead>
            <tr>
                <th></th>
                <th>C1</th>
                <th><i class="font-xs"></i> C2</th>
                <th><i class="font-xs"></i> C3</th>
                <th><i class="text-muted hidden-md hidden-sm hidden-xs"></i> C4</th>
                <th><i class="text-muted hidden-md hidden-sm hidden-xs"></i> C5</th>
                <th><i class="text-muted hidden-md hidden-sm hidden-xs"></i>C6</th>
                <th>C7</th>
                <th>C8</th>

            </tr>
        </thead>
        <tbody>
            
            <tr>
                <td class="clstest" id="X1" style="cursor: pointer; cursor: hand;"><span class="glyphicon glyphicon-plus-sign pl"></span></td>
                <td class="editpro UpdateX" data-projname="Xname" data-toggle="modal" data-target="#myXName" data-backdrop="static" data-keyboard="false" data-id="XId" style="cursor: pointer; cursor: hand;"><span class="EditXName">X1Name</span></td>
                <td>X2Source</td>
                <td>
                    X31,X32,X33


                </td>
                <td>11-01-2017</td>
                <td>15--2-2017</td>
                <td>True</td>
                <td>
                    X41
                </td>
                <td data-projid="XId" class="fid">
                    <div class="row">
                        <table>
                            <tr>
                                <td>
                                    <div class="image-upload dvhover">
                                        &nbsp;&nbsp;<label for="file-input" class="glyphicon glyphicon-cloud-upload" style="cursor: pointer; color:#607bbb;" title="Upload File"></label>
                                        <input id="file-input" class="fileup" type="file" accept=".resx, .zip, .rar" />&nbsp;
                                    </div>
                                </td>

                               
                                <td>
                                    <div class="dvhover dvDownload">
                                        <label class="glyphicon glyphicon-cloud-download" style="cursor: pointer; color:#607bbb;" title="Download File(s)"></label>&nbsp;
                                    </div>
                                </td>
                                
                                <td>
                                    <div class="dvhover">
                                        <span class="glyphicon glyphicon-send btnsend" style="cursor: pointer; color:#607bbb;" title="Send"></span>&nbsp;
                                    </div>
                                </td>
                               
                                <td><div class="dvhover"><span class="glyphicon glyphicon-trash deleteid" data-did="XId" style="cursor: pointer; color:#607bbb;" title="Delete Project"></span>&nbsp;</div></td>
                                <td><div class="dvhover"><span class="glyphicon glyphicon-remove btnreject" style="cursor: pointer; color:#607bbb;" title="Cancel Project"></span>&nbsp;</div></td>
                                

                            </tr>
                        </table>
                    </div>
                </td>

            </tr>
            
        </tbody>
    </table>

Теперь я хочу, чтобы при щелчке по классу fileup, который является элементом управления загрузкой файлов (если вы видите фрагмент), значение в td (class = "UpdateX"), т. Е. Значение столбца C1 из той же строки, будет отображаться в предупреждении. , Пожалуйста, помогите.

0
Mahatma Aladdin 13 Янв 2017 в 10:58

4 ответа

Лучший ответ
$(document).on('click', '.fileup', function (event) {
    var val = $(this).parents('tr').find('td.UpdateX').text();
    alert(val);
    event.preventDefault();
});
1
Rajbir Sharma 13 Янв 2017 в 08:43

Это должно сделать свое дело.

$(document).on('click', '.fileup', function()
{
    var parent = $(this).parents('td.fid');
    var grandParent = $(parent).parents('tr');

    var value = $(grandParent).find('td.UpdateX .EditXName').text();

    alert(value);
});
0
Medard 13 Янв 2017 в 08:26

ДЕМО Клик

< Сильный > Javascript

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>

<script type="text/javascript">
$(document).ready(function()
{
    $('.fileup').on('click', function(){

    var Result = $(this).parents('tr').closest('tr').find('td.UpdateX').text();

    alert(Result);

    });
});
</script>

< Сильный > HTML

<table width="100%" border="1">
<thead>
    <tr>
        <th></th>
        <th>C1</th>
        <th><i class="font-xs"></i> C2</th>
        <th><i class="font-xs"></i> C3</th>
        <th><i class="text-muted hidden-md hidden-sm hidden-xs"></i> C4</th>
        <th><i class="text-muted hidden-md hidden-sm hidden-xs"></i> C5</th>
        <th><i class="text-muted hidden-md hidden-sm hidden-xs"></i>C6</th>
        <th>C7</th>
        <th>C8</th>
    </tr>
</thead>
<tbody>

    <tr>
        <td class="clstest" id="X1" style="cursor: pointer; cursor: hand;"><span class="glyphicon glyphicon-plus-sign pl"></span></td>
        <td class="editpro UpdateX" data-projname="Xname" data-toggle="modal" data-target="#myXName" data-backdrop="static" data-keyboard="false" data-id="XId" style="cursor: pointer; cursor: hand;"><span class="EditXName">X1Name</span></td>
        <td>X2Source</td>
        <td>X31,X32,X33</td>
        <td>11-01-2017</td>
        <td>15--2-2017</td>
        <td>True</td>
        <td>X41</td>
        <td data-projid="XId" class="fid">
        <div class="row">
        <table>
            <tr>
                <td>
                    <div class="image-upload dvhover">
                        &nbsp;&nbsp;<label for="file-input" class="glyphicon glyphicon-cloud-upload" style="cursor: pointer; color:#607bbb;" title="Upload File"></label>
                        <input id="file-input" class="fileup" type="file" accept=".resx, .zip, .rar" />&nbsp;
                    </div>
                </td>                       
                <td>
                    <div class="dvhover dvDownload">
                        <label class="glyphicon glyphicon-cloud-download" style="cursor: pointer; color:#607bbb;" title="Download File(s)"></label>&nbsp;
                    </div>
                </td>
                <td>
                    <div class="dvhover">
                        <span class="glyphicon glyphicon-send btnsend" style="cursor: pointer; color:#607bbb;" title="Send"></span>&nbsp;
                    </div>
                </td>                       
                <td>
                    <div class="dvhover"><span class="glyphicon glyphicon-trash deleteid" data-did="XId" style="cursor: pointer; color:#607bbb;" title="Delete Project"></span>&nbsp;</div>
                </td>
                <td>
                <div class="dvhover"><span class="glyphicon glyphicon-remove btnreject" style="cursor: pointer; color:#607bbb;" title="Cancel Project"></span>&nbsp;</div>
                </td>
            </tr>
        </table>
        </div>
        </td>
    </tr>

    <tr>
        <td class="clstest" id="X1" style="cursor: pointer; cursor: hand;"><span class="glyphicon glyphicon-plus-sign pl"></span></td>
        <td class="editpro UpdateX" data-projname="Xname" data-toggle="modal" data-target="#myXName" data-backdrop="static" data-keyboard="false" data-id="XId" style="cursor: pointer; cursor: hand;"><span class="EditXName">2X1Name</span></td>
        <td>2X2Source</td>
        <td>2X31,X32,X33</td>
        <td>11-01-2016</td>
        <td>15--2-2016</td>
        <td>True</td>
        <td>2X41</td>
        <td data-projid="XId" class="fid">
        <div class="row">
        <table>
            <tr>
                <td>
                    <div class="image-upload dvhover">
                        &nbsp;&nbsp;<label for="file-input" class="glyphicon glyphicon-cloud-upload" style="cursor: pointer; color:#607bbb;" title="Upload File"></label>
                        <input id="file-input" class="fileup" type="file" accept=".resx, .zip, .rar" />&nbsp;
                    </div>
                </td>                       
                <td>
                    <div class="dvhover dvDownload">
                        <label class="glyphicon glyphicon-cloud-download" style="cursor: pointer; color:#607bbb;" title="Download File(s)"></label>&nbsp;
                    </div>
                </td>
                <td>
                    <div class="dvhover">
                        <span class="glyphicon glyphicon-send btnsend" style="cursor: pointer; color:#607bbb;" title="Send"></span>&nbsp;
                    </div>
                </td>                       
                <td>
                    <div class="dvhover"><span class="glyphicon glyphicon-trash deleteid" data-did="XId" style="cursor: pointer; color:#607bbb;" title="Delete Project"></span>&nbsp;</div>
                </td>
                <td>
                <div class="dvhover"><span class="glyphicon glyphicon-remove btnreject" style="cursor: pointer; color:#607bbb;" title="Cancel Project"></span>&nbsp;</div>
                </td>
            </tr>
        </table>
        </div>
        </td>
    </tr>

    <tr>
        <td class="clstest" id="X1" style="cursor: pointer; cursor: hand;"><span class="glyphicon glyphicon-plus-sign pl"></span></td>
        <td class="editpro UpdateX" data-projname="Xname" data-toggle="modal" data-target="#myXName" data-backdrop="static" data-keyboard="false" data-id="XId" style="cursor: pointer; cursor: hand;"><span class="EditXName">3X1Name</span></td>
        <td>3X2Source</td>
        <td>3X31,X32,X33</td>
        <td>11-01-2015</td>
        <td>15--2-2015</td>
        <td>True</td>
        <td>3X41</td>
        <td data-projid="XId" class="fid">
        <div class="row">
        <table>
            <tr>
                <td>
                    <div class="image-upload dvhover">
                        &nbsp;&nbsp;<label for="file-input" class="glyphicon glyphicon-cloud-upload" style="cursor: pointer; color:#607bbb;" title="Upload File"></label>
                        <input id="file-input" class="fileup" type="file" accept=".resx, .zip, .rar" />&nbsp;
                    </div>
                </td>                       
                <td>
                    <div class="dvhover dvDownload">
                        <label class="glyphicon glyphicon-cloud-download" style="cursor: pointer; color:#607bbb;" title="Download File(s)"></label>&nbsp;
                    </div>
                </td>
                <td>
                    <div class="dvhover">
                        <span class="glyphicon glyphicon-send btnsend" style="cursor: pointer; color:#607bbb;" title="Send"></span>&nbsp;
                    </div>
                </td>                       
                <td>
                    <div class="dvhover"><span class="glyphicon glyphicon-trash deleteid" data-did="XId" style="cursor: pointer; color:#607bbb;" title="Delete Project"></span>&nbsp;</div>
                </td>
                <td>
                <div class="dvhover"><span class="glyphicon glyphicon-remove btnreject" style="cursor: pointer; color:#607bbb;" title="Cancel Project"></span>&nbsp;</div>
                </td>
            </tr>
        </table>
        </div>
        </td>
    </tr>

</tbody>
</table>
0
J.K 13 Янв 2017 в 08:47

Вы можете попробовать следующий код:

$(document).on('click', '.fileup', function () {
    alert($(this).parents('tr').find('td.UpdateX').text());
});
0
Himanshu Vohra 13 Янв 2017 в 08:15