我设计了一个ascx控件(我在这个问题中将其称为customControl)。该控件只是一系列的下拉列表,每个下拉列表中都有文本值。下拉菜单位于面板内部。
如下所示:
然后我把它们中的一些放在一个也有文本框的页面上(我在这里把它称为文本框)
如下所示:
所以我需要开发的是Javascript,当任何customControls中的任何下拉列表都有一个选定的下拉索引更改事件时,它可以找到页面上类型为customControl的所有控件的所有框中的所有值,并简单地将文本放入文本框中。
我是否需要定义我的控件来拥有一个类,这样JS就可以很容易地找到它们,然后让JS函数将textbox作为控件,这样它就知道要输出什么以及输出到哪里?
发布于 2009-08-12 11:41:24
使用css类"customControlDropDown“或其他值设置所有下拉列表,并使用css类名"bigTextBox”或其他值设置文本框并使用一些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-12 11:18:46
在你的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>
https://stackoverflow.com/questions/1267568
复制相似问题