带有 ascx 控件的 Javascript

发布于 2024-08-01 14:10:02 字数 512 浏览 4 评论 0原文

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

如下所示:

control

然后我将其中一些放在也有文本框的页面上(我指的是它这里是文本框)

如下:

Series of control

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

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

I designed an ascx control (I refer to it in this question as customControl). The control is just a series of drop downs with text values in each drop down. The drop downs are inside a panel.

Here it is below:

control

I then place a few of them on a page that also has a textbox (I refer to it here as textbox)

Here it is below:

Series of control

So what I need to develop, is Javascript that when any of the drop downs in any of the customControls have a selected drop down index changed event, to find all the values in all the boxes of all the controls of type customControl on the page and simply put that text in the textbox.

Do I need to define my control to have a class so JS can find all of them easily and then have the JS function take in the textbox as control so it knows what to output and where?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏天碎花小短裙 2024-08-08 14:10:02

使用“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>

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

Set all your drop downs with a css class of "customControlDropDown" or whatever and your textbox with a css class name of "bigTextBox" or whatever and use some 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>

I haven't tested this, but it SHOULD work. Let us know.

过潦 2024-08-08 14:10:02

在你的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>

in yours ascx control, must have the class "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;
    }

}

in html or aspx:

<div id="container>
   <!-- aspx controls -->
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文