2009-08-12 64 views
0

我设计了一个ascx控件(我指的是它在这个问题作为customControl)。控件只是一系列下拉菜单中的文本值。下拉菜单位于面板内。的Javascript的ascx控件

这是如下:

control

然后我把他们几个人的页面,也有一个文本框上(我指的是在这里为文本框)

这低于:

Series of control

所以我发展的需要,是的Javascript,当任何一个下拉菜单中任意t的他customControls有一个选择的下拉指数变化的情况下,要找到所有的值在页面上类型customControl的所有控件的所有的箱子,并简单地把在文本框中的文本。

我需要定义我的控制有一个类,因此JS可以很容易地找到所有的人,然后让JS功能您可以在文本框的控制,所以它知道什么输出,在哪里?

在你的ascx控件
+0

您可以使用jQuery? – 2009-08-12 18:49:24

回答

2

设置你所有的下拉菜单有一个CSS类“customControlDropDown”或什么,你的文本框与“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> 

我没有测试过这个,但它应该工作。让我们知道。

0

,必须有一流的 “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>