下拉列表选择

时间:2013-02-04 00:00:28

标签: javascript html function select onclick

在DropDownList中选择Item时,我可以帮助调用Javascript函数(getSelectedFilterText)。

这是我的代码:

<select id="FeedBackFilter" name="FeedBackFilter" width="2000" onclick="getSelectedFilterText">
    <option value="All">All</option>
    <option value="Bad">Bad</option>
    <option value="Good">Good</option>
    <option value="Both">Both</option>
</select>

function getSelectedFilterText()
{
    alert("test");
    var e = document.getElementById("FeedBackFilter");
    var strUser = e.options[e.selectedIndex].text;
    alert(strUser);
}

我做错了什么?

1 个答案:

答案 0 :(得分:0)

首先你需要像这样的括号:

onclick="getSelectedFilterText()"

但是如果你只是想在改变选择时发生这种情况,你应该考虑改为使用'onchange'这样的事件:

onchange="getSelectedFilterText()"

这种方式会在他们更改选项时发生,而不是在他们点击它时...这是不同的,他们可以点击它而不更改选项