0

您好,感谢您的帮助,

我试图在我的页面加载时设置下拉框的值。现在它没有给我任何错误,但是 dang 下拉框没有设置为我想要的值。

这是我的代码:

<body onLoad="IssuesToReportForm.ReportTo.SelectedValue = '<%=strReportTo%>'">

这部分代码是我的问题吗?

谢谢,威尔

4

1 回答 1

0
<script type="text/javascript">
  function PreselectMyItem(itemToSelect)
  {

    // Get a reference to the drop-down
    var myDropdownList = document.IssuesToReportForm.ReportTo;

    // Loop through all the items
    for (iLoop = 0; iLoop< myDropdownList.options.length; iLoop++)
    {    
      if (myDropdownList.options[iLoop].value == itemToSelect)
      {
        // Item is found. Set its selected property, and exit the loop
        myDropdownList.options[iLoop].selected = true;
        break;
      }
    }

  }
</script>

假设IssuesToReportForm是您的表单名称和ReportTo下拉列表的名称。

然后<body onLoad="PreselectMyItem('<%=strReportTo%>')">

来源

于 2009-12-21T16:47:36.503 回答