Javascript启用/禁用asp DropDownList显示时髦的行为?

时间:2009-12-31 17:17:13

标签: javascript asp.net drop-down-menu

单击按钮时禁用下拉列表

function disableDropDown(DropDownID)
{
  document.getElementById(DropDownID).disabled = true;
  return false; <---------tried with and without this, no luck
}

和onClick调用

disableDropDown('DropDownID');

我看到它禁用下拉列表,然后立即发生回发,使其恢复。有人可以解释这里可能有什么问题吗?

3 个答案:

答案 0 :(得分:1)

ASP.NET Button控件是否调用它?这可能是您的网页回发的原因。

尝试使用常规的html输入按钮。

<input type="button" onclick="disableDropDown('DropDownID');" />

答案 1 :(得分:0)

听起来你可能会将这个附加到发回的asp:Button

您真正需要的只是<input type="button">或甚至只是<button>元素

<button onclick="disableDropDown(DropDownID);">Disable DropDown</button>

答案 2 :(得分:0)

    function EnableDisableControl(source, Chk, ddl) 
{
    if (source.checked == false) {
        document.getElementById(ddl).selectedIndex = 0;
        document.getElementById(source.id.replace(Chk, ddl)).disabled = !source.checked;
    }
    else {
        document.getElementById(source.id.replace(Chk, ddl)).disabled = !source.checked;
    }
}