0

我设计了一个 ascx 控件(我在这个问题中将它称为 customControl)。该控件只是一系列下拉菜单,每个下拉菜单中都有文本值。下拉菜单位于面板内。

下面是:

控制

然后我将其中一些放在一个也有文本框的页面上(我在这里将其称为文本框)

下面是:

系列控制

所以我需要开发的是Javascript,当任何customControls中的任何下拉菜单具有选定的下拉索引更改事件时,在页面上找到所有customControl类型控件的所有框中的所有值和只需将该文本放在文本框中。

我是否需要将我的控件定义为有一个类,以便 JS 可以轻松找到所有这些,然后让 JS 函数将文本框作为控件接收,以便它知道要输出什么以及在哪里输出?

4

2 回答 2

2

使用“customControlDropDown”或其他任何css类设置所有下拉菜单,并使用“bigTextBox”或其他任何css类名称设置文本框,并使用一些jQuery。

<script type='text/javascript'>
   $(document).ready(function(){
      $("select.customControlDropDown").change(function(){ //change event for all drop downs with customControlDropDown as its css class name
         var collectiveText = "";
         $("select.customControlDropDown option:selected").each(function(i){  //get all selected options in all the drop downs with customControlDropDown as its css class name
            collectiveText = collectiveText + $(this).text(); //append the item's text to a string variable
         });

         $(".bigTextBox").val(collectiveText); //set the textbox with css class name of bigTextBox with value of the string variable from above
      });
   });
</script>

我没有对此进行测试,但它应该可以工作。让我们知道。

于 2009-08-12T19:41:23.613 回答
0

在您的 ascx 控件中,必须具有“myClass”类。

window.onload = function(){
    function getElementsByClass(containerId, class) 
    { 
      container = document.getElementById(containerId);
      var all = container.all¦¦container.getElementsByTagName('*') ;
      var arr = [] 
      for(var k=0;k<all.length;k++) 
        if(all[k].getAttribute("class").indexOf("class") != -1) 
          arr[arr.length] = all[k];
      return arr;
    }

    var arrEl = getElementsByClass("container", "myClass");
    var xOnChange = function()
    {
       //this
    }

    for (var ind = 0; ind < arEL.length; ind++)
    {
       arrEl[ind].onchange = xOnChange;
    }

}

在 html 或 aspx 中:

<div id="container>
   <!-- aspx controls -->
</div>
于 2009-08-12T19:18:46.467 回答