本文介绍了jquery等效/浏览器兼容e.parentNode.parentNode.childNodes [i] .innerText;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码段来更新表格中的某些文本框值。

I am using the following snippet for updating some textbox value from a table.

          <table>
               <tr>
                <td>
                    ProjectName
                </td>
                <td>
                    Block
                </td>
                <td>
                    .WorkProgressMilestone
                </td>
                <td>
                    Completion
                </td>

                 <td>
                    <span class="sep">
                        <img height="15px" width="20px" src="@Url.Content("~/Content/themes/base/images/Edit.png")" /></span><a
                            href="#" onclick="EditWorkDetails(this);" style="text-decoration: none">Edit</a>
                    <input id="WorkProgressEditID" name="WorkProgressEditID" type="hidden" value="@v.WorkProgressID" />
                </td>
      </tr>
     <tr>..</tr>
 </table>



function EditWorkDetails(e) {
document.getElementById("txtCompletion").value =        e.parentNode.parentNode.childNodes[3].innerText;
}

在IE中它适用于我,但在其他浏览器中无效(Chrome )。值得注意的是,表'td'和'tr'没有Id属性来区分对方。所以我不能在这里使用jquery。我可以遵循什么替代方案使其适用于所有浏览器。

It works fine for me in IE, but not working in other browsers(Chrome). A notable thing is that the table 'td's and 'tr's don't have Id property to distinguish each other. So I can't use jquery over here. What is the alternative I can follow to make it work in all browsers.

推荐答案

试试这个:

document.getElementById("txtCompletion").value = $(this).parent().parent().children()[3].html();

$("txtCompletion").val($(this).parent().parent().children()[3].html());

这篇关于jquery等效/浏览器兼容e.parentNode.parentNode.childNodes [i] .innerText;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 04:49