2009-08-12 3 views
0

ascx 컨트롤을 디자인했습니다.이 질문은 customControl로 지정했습니다. 컨트롤은 각 드롭 다운의 텍스트 값이있는 일련의 드롭 다운에 지나지 않습니다. 드롭 다운은 패널 안에 있습니다.ascx 컨트롤을 사용하는 자바 스크립트

여기가 아래와 같습니다 :

control

그때 또한 텍스트 상자가있는 페이지에 그들 중 몇 가지를 배치 여기

그것은 다음과 같습니다 (I는 텍스트 상자로 여기 참조) :

Series of control

그래서 개발하기 위해 필요한, 자바 스크립트가 있다는 것입니다 경우 t의에서 드롭 다운의 그 customControls에는 페이지에서 customControl 유형의 모든 컨트롤에있는 모든 상자의 모든 값을 찾고 해당 텍스트를 텍스트 상자에 넣기 위해 선택된 드롭 다운 인덱스 변경 이벤트가 있습니다.

JS가 모두 쉽게 찾을 수 있도록 JS를 제어 할 수 있도록 정의해야하며 JS 함수가 텍스트 상자를 컨트롤로 받아서 출력 할 내용과 위치를 알고 있어야합니다.

+0

jQuery를 사용할 수 있습니까? –

답변

2

설정 모든 드롭 다운 : HTML 또는 영문의

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; 
    } 

} 

일부 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

ascx 컨트롤에서 "myClass"클래스가 있어야합니다. CSS 클래스의 "bigTextBox"의 이름이나 어떤 사용과 CSS를 "customControlDropDown"의 클래스 또는 무엇이든 당신의 텍스트 상자에

<div id="container> 
    <!-- aspx controls --> 
</div> 
관련 문제