简体   繁体   English

如何使用“ fireEvent”方法从aspx页面java脚本标签返回值?

[英]How to return a value from aspx page java script tag using “fireEvent” method?

I am having multiple dropdownlists in my aspx page. 我的aspx页面中有多个dropdownlists。 Reletively I am populating all the dropdownlists one by one. 我要一遍又一遍地填充所有下拉列表。 The last dropdown list selected value should be returned to the calling environment when I click on the button. 当我单击按钮时,最后一个下拉列表选择的值应返回到调用环境。 For that I added a script tag in aspx page and written a function which is working as onClick event. 为此,我在aspx页面中添加了一个脚本标记,并编写了一个函数作为onClick事件。 Please explain me how to create the event with that value and fire using fireEvent method. 请向我解释如何创建具有该值的事件并使用fireEvent方法触发。 If it is not possible through fireEvent method please suggest any other way. 如果无法通过fireEvent方法实现,请提出其他建议。

What do you mean by "returned to the calling environment"? “返回到呼叫环境”是什么意思? If you want to show the selected value ,just use 如果要显示所选值,请使用

var e = document.getElementById("ddl");
var valueddl= e.options[e.selectedIndex].value;

To bind the value 绑定值

function fireEvent(element,event){
    if (document.createEventObject){
    // dispatch for IE
    var evt = document.createEventObject();
    return element.fireEvent('on'+event,evt)
    }
    else{
    // dispatch for firefox + others
    var evt = document.createEvent("HTMLEvents");
    evt.initEvent(event, true, true ); // event type,bubbling,cancelable
    return !element.dispatchEvent(evt);
    }
}

[html]
<input type="text" id="test">
<input type="text" id="testafterfired">
<script>
obj = document.getElementById("test");
Event.observe(obj,'change',function(){var e = document.getElementById("ddl");
var valueddl= e.options[e.selectedIndex].value;document.getElementById("testafterfired").value=valueddl;});
obj.fire('change');

</script>
[/html]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM