带有ascx控件的Javascript

带有ascx控件的Javascript,javascript,c#,.net,ascx,Javascript,C#,.net,Ascx,我设计了一个ascx控件(我在这个问题中将其称为customControl)。控件只是一系列下拉列表,每个下拉列表中都有文本值。下拉列表位于面板内 以下是: 然后我将其中一些放在一个页面上,该页面也有一个文本框(我在这里称之为文本框) 以下是: 所以我需要开发的是Javascript,当任何customControl中的任何下拉菜单有一个选定的下拉索引更改事件时,在页面上customControl类型的所有控件的所有框中查找所有值,并将该文本放入文本框中 我是否需要定义我的控件来拥有一个类,

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

以下是:

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

以下是:

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


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

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

window.onload=function(){
函数getElementsByClass(containerId,类)
{ 
container=document.getElementById(containerId);
var all=container.allαcontainer.getElementsByTagName('*');
var arr=[]

对于(var k=0;k将所有下拉列表设置为css类“customControlDropDown”或其他名称,将文本框设置为css类名“bigTextBox”或其他名称,并使用一些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>

$(文档).ready(函数(){
$(.select.customControlDropDown”).change(function(){//change事件,用于所有以customControlDropDown作为css类名的下拉列表
var collectiveText=“”;
$(“select.customControlDropDown选项:selected”)。每个(函数(i){//获取所有下拉列表中的所有选定选项,并将customControlDropDown作为其css类名
collectiveText=collectiveText+$(this).text();//将项的文本追加到字符串变量
});
$(“.bigTextBox”).val(collectiveText);//使用上面的字符串变量值设置css类名为bigTextBox的文本框
});
});
我还没有测试过这个,但它应该可以工作。让我们知道

<div id="container>
   <!-- aspx controls -->
</div>
<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>