如何JavaScript函数添加到使用ASP事件:组合框 [英] How to add javascript functions to events using ASP:ComboBox

查看:125
本文介绍了如何JavaScript函数添加到使用ASP事件:组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请怜悯,在ASP工作不是我的原生环境。我有一个组合框是页面的加载过程中使用ListItems的填充。我需要的信息了所选项目的价值,当用户选择的一个条目,但对于每一个事件的钩子我已经试过什么也没有做。

Please have mercy, working in ASP is not my native environment. I have a ComboBox that is populated with ListItems during the load of the page. I need to get information out of the selected items value when the user selects one of the entries, but every hook for an event I have tried has done nothing.

我能做些什么,以使所选择的指数变化解雇我的JavaScript?

What can I do to cause a selected index change to fire my Javascript?

控制:< ASP:组合框ID =cboFighterGymNAME =cboFighterGym=服务器的AutoPostBack =FALSE
                                            DropDownStyle =DropDownList的AutoCompleteMode =SuggestAppend的CaseSensitive =FALSE
                                            ItemInsertLocation =追加的onchange =你好();的ClientIDMode =静态>
                                        < / ASP:组合框>

var sel = document.getElementById("cboFighterGym");
        alert(sel.toString()); // This outputs [object HTMLDivElement]
        sel.onchange = function () {
            alert("Selected value: " + this.value); // This never happens
        };

当我运行它的部分似乎是这样的:

When I run it the section appears to look like this:

<div id="cboFighterGym" name="cboFighterGym" onchange="hello();" onFocus="alert(&#39;Hello&#39;)" style="display:inline-block;">
<table id="Table" class="ajax__combobox_inputcontainer" cellspacing="0" cellpadding="0" style="border-width:0px;border-style:None;border-collapse:collapse;display:inline-block;position:relative;top:5px;">
    <tr>
        <td class="ajax__combobox_textboxcontainer"><input name="cboFighterGym$TextBox" type="text" id="TextBox" autocomplete="off" /></td><td class="ajax__combobox_buttoncontainer"><button id="Button" type="button" style="visibility:hidden;"></button></td>
    </tr>
</table><ul id="OptionList" class="ajax__combobox_itemlist" style="display:none;visibility:hidden;">
    <li>Select a Gym</li><li>Other</li><li>555 555, Oregon</li>

</ul><input type="hidden" name="cboFighterGym$HiddenField" id="HiddenField" value="0" />

推荐答案

如果你使用asp.net 4,可以利用新的的ClientIDMode ,给你的下拉列表中选择predictable名称,然后选择它并订阅的JavaScript

If you're using asp.net 4, you can utilize the new ClientIDMode, to give your dropdown a predictable name, then select it and subscribe to the onchange event in JavaScript

<asp:DropDownList runat="server" ID="selectId" ClientIDMode="Static" />

var sel = document.getElementById("selectId");
sel.onchange = function(){
    alert("Selected value: " + this.value);
};

或者你可以给它一个独特的类名,而且基本上做同样的事情:

Or you can give it a unique classname, and essentially do the same thing:

var sel = document.getElementsByClassName("uniqueClass")[0];
sel.onchange = function(){
    alert("Selected value: " + this.value);
};

这篇关于如何JavaScript函数添加到使用ASP事件:组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆