问题描述
我有一个名为"drop_category"的下拉列表,例如:
-Category1
-Category2
-Category3
-Category4
-添加新类别
并且我希望用户选择项目添加新类别"时,网络将打开一个弹出窗口
我试过了
i have a Drop Down List called "drop_category" like:
-Category1
-Category2
-Category3
-Category4
-Add new category
and i want the web will open a popup when user select item "Add new category"
i tried
drop_category.Items.FindByText("Add new category").Attributes.Add("onfocus", "newCate()");
--
function newCate() {
window.open(''Category_Manage.aspx'', null, ''height=250, width=250,status= no, resizable= no, scrollbars=no, toolbar=no,location=no,menubar=no '');
return false;
但它不起作用.我该怎么办?
非常感谢您的帮助.
but it not work. How i can do it?
I would really appreciate your help
推荐答案
drop_category.Attributes.Add("onChange", "newCate();");
在js后面的代码中
in the code behind and in the js
function newCate() {
var e = document.getElementById('ctl00_<panelname>_drop_category');
if (e.options[e.selectedIndex].value == '0')
window.open('Category_Manage.aspx', null, 'height=250, width=250,status= no, resizable= no, scrollbars=no, toolbar=no,location=no,menubar=no ');
return false;
}
用您拥有的任何值替换该值.请注意,您在javascript中的控件名称可能有所不同.如果您的JavaScript内联,则可以使用ClientId检索以html呈现的下拉列表名称.像这样:
Replace the value with whatever value you have. Do Note that your control name in javascript may be different. If you have your javascript as inline you can use the ClientId to retrieve the drop down''s name when it is rendered in html. Like this:
document.getElementById('<%= this.drop_category.ClientID %>');
这篇关于下拉列表项事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!