1

我有一个正在尝试处理的脚本。我希望能够找到父 id,以便我可以调整它的样式背景颜色。我还想在父 div 内的某个“输入”中插入一个值。

function changeBGC(color) {
    var testObj = this.parentNode;
    document.getElementById(testObj).style.backgroundColor = color;
}

function changeValue(value) {
    var changer = document.getElementById('DIVELEMENT?');
    changer.value = value;
}​

所有这些都在 Divs 中完成。我知道我可以定义一个特定的 id 或类,但我的网站设计的所有 DIV 的名称都相同。所以我只希望脚本在那些特定的 Div 中工作。

任何人都可以请帮忙。我似乎无法弄清楚,我主要认为这只是我需要的parent.id。

4

0 回答 0