有没有办法获取当前脚本标签的父节点。我想为 script 标签分配 id 属性,但发现它不支持标准属性。
实际上我想获取框架内文档的标题,而 document.title 返回网页的标题。
如果我有一个TreeView(myTreeview),我怎样才能获得作为父节点的所有节点的列表?即有孩子的节点
如果更改下拉列表中的选定项目,我正在尝试更改表格单元格的背景颜色.我使用相同的JavaScript文本框,它工作正常.在firebug中,当从select中调用时,"cell"是未定义的.
这是我的脚本/ html
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function changeText(cell, shown, hidden)
{
if (shown == hidden)
{
cell.style.backgroundColor="red";
}
else
{
cell.style.backgroundColor="green";
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table cellpadding="5">
<tr>
<td>
Cell 1
</td>
<td>
<select id="catBlah" OnChange="changeText(this.parentnode, this.options[this.selectedIndex].value, '789');">
<option value=""></option>
<option selected="selected" value="789">Item 1</option>
<option value="000">Item 2</option>
<option value="456">Item 3</option>
<option value="123">Item 4</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="text" value="blue" onchange="changeText(this.parentNode, this.value, 'blue');" />
</td>
<td>
Cell 4
</td> …Run Code Online (Sandbox Code Playgroud) 现在我有这个代码:
<script type="text/javascript">
function delete_box(n) {
document.getElementById("box"+n).style.display = "none";
}
<script>
<div id="box1">
<table>
<td>some code</td><td><input type="button" value="Delete this box" onclick="delete_box(1)"></td>
</table>
</div>
Run Code Online (Sandbox Code Playgroud)
它工作正常。当我按下按钮时,框消失了。但是我想简化并像这样:
<script type="text/javascript">
function delete_box(n) {
document.getElementById(n).style.display = "none";
}
<script>
<div id="box1">
<table>
<td>some code</td><td><input type="button" value="Delete this box" onclick="delete_box(this.parentnode.id)"></td>
</table>
</div>
Run Code Online (Sandbox Code Playgroud)
但是它不会按预期工作。控制台说 id 为空,我不知道为什么。我做错了什么?
谢谢你。
parent-node ×4
javascript ×3
c# ×1
document ×1
frame ×1
html ×1
html-select ×1
title ×1
treeview ×1
winforms ×1