0

我有选项选择(称为selection)。

当用户更改所选行时,有onchange以下功能:

<select id="selection" style="width: 276px;" onchange="func(this,'previewBody')">

我有一个javascript代码:

var e = document.getElementById("selection");
if ((e.options[i].text).search("5191") != -1) {
      e.selectedIndex = i; // select the row in the option
      //func(this, 'previewBody'); // HERE I have to run this function

}

但我应该发送什么?如何创建this像函数this的变量onchange

任何帮助表示赞赏!

4

2 回答 2

4

只需使用保存元素的变量的名称:

var elem = document.getElementById("selection");
if ((elem.options[i].text).search("5191") != -1) {
    elem.selectedIndex = i;
    func(elem, "previewBody");
}
于 2013-06-10T13:50:03.060 回答
3

您的 onchange 声明中的“this”将是 ID 为“selection”的选择框。因此,如果你传递“e”,你应该有一个等效的调用。

于 2013-06-10T13:49:00.743 回答