2 回答

TA貢獻1775條經(jīng)驗 獲得超11個贊
“#”這是一個類。它不是元素或 id。它用于為您的 CSS 頁面設置樣式。要設置 id,您可以在 HTML 或 javascript 中執(zhí)行此操作。html:
id="fname"
javascript:
let text = document.createElement('p');
//notice that you are assigning this element to "text" and then setting it's id.
text.id = "cellText";
所以假設您將id設置為“focusRect”并將其分配給“rectang”(這樣let = document.getElementById("focusRect")您每次都可以通過rectang引用對象。(查找dom:文檔對象模型對您有幫助)。
rectang.style.border = "thick solid #0000FF";

TA貢獻1784條經(jīng)驗 獲得超2個贊
<table>
<tr onclick="myFunction(this)">
<td>Click to show rowIndex</td>
</tr>
<tr onclick="myFunction(this)">
<td>Click to show rowIndex</td>
</tr>
<tr onclick="myFunction(this)">
<td>Click to show rowIndex</td>
</tr>
<tr onclick="myFunction(this)">
<td>Click to show rowIndex</td>
</tr>
</table>
function myFunction(x) {
console.log("Row index is: " + x.rowIndex);
}
添加回答
舉報