0

ascx コントロールを設計しました (この質問では customControl と呼びます)。コントロールは、各ドロップダウンにテキスト値を持つ一連のドロップダウンです。ドロップダウンはパネル内にあります。

ここでは以下です:

コントロール

次に、テキストボックスもあるページにそれらのいくつかを配置します (ここではテキストボックスと呼びます)。

ここでは以下です:

一連の制御

したがって、私が開発する必要があるのは、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 に答える