我正在使用以下代码片段来更新表中的某些文本框值。
<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's 和 'tr's 没有 Id 属性来区分彼此。所以我不能在这里使用jquery。我可以采用什么替代方案来使其在所有浏览器中运行。
最佳答案
试试这个:
document.getElementById("txtCompletion").value = $(this).parent().parent().children()[3].html();
或
$("txtCompletion").val($(this).parent().parent().children()[3].html());
关于javascript - e.parentNode.parentNode.childNodes[i].innerText 的 Jquery 等效/浏览器兼容性;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12635751/