2009-08-12 14 views
0

私はascxコントロールを設計しました(この質問ではcustomControlと呼んでいます)。コントロールは、各ドロップダウンのテキスト値を含む単なる一連のドロップダウンです。ドロップダウンはパネル内にあります。ascxコントロールを使用したJavascript

ここで、それは以下の通りです:

control

私は、その後も、テキストボックスを持っているページ上でそれらのいくつかを置く(私はテキストボックスとして、ここでそれを参照してください)

ここでは、以下の通りです:

Series of control

だから私は、開発に必要なもの、Javascriptがその時にドロップダウンのいずれかのトンのいずれかであります彼はcustomControlsには、ページ上のcustomControl型のすべてのコントロールのすべてのボックスのすべての値を検索し、テキストボックスにそのテキストを配置するために、選択されたドロップダウンインデックス変更イベントがあります。

JSがそれらのすべてを簡単に見つけることができるようにコントロールを定義する必要がありますし、JS関数がテキストボックスをコントロールとして受け取り、何を出力するのかを知ることができます。

+0

jQueryを使用できますか? –

答えて

2

:HTMLやASPXで

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」の名前または何と使用して「customControlDropDown」または何とあなたのテキストボックスのCSSクラスで、すべてのドロップダウンを設定し
<div id="container> 
    <!-- aspx controls --> 
</div> 
関連する問題