我对下拉验证有疑问 [英] I have question about the Dropdown Validation
问题描述
Flowing Dropdown Validation不起作用(Tab键或移动光标)?什么是错误。有人plz帮助我??数据绑定此下拉菜单。
Flowing Dropdown Validation Not work( tabbing or by moving the cursor)?? what is the error.anyone plz help me??data bound this dropdown.
function LoseFocus(ddlElem) {
ddlElem.blur();
var val = ddlElem.options[e.selectedIndex].value;
if (val == "" || val == "Select")
alert('Error');
}
-------------------------- -------------------------------------------------- ----------------
--------------------------------------------------------------------------------------------
<asp:DropDownList ID="DropDownCountry" runat="server" AutoPostBack="true"
CssClass="input" Height="20px"
onselectedindexchanged="DropDownCountry_SelectedIndexChanged" TabIndex="18"
Width="99%" onchange="LoseFocus(this);" >
</asp:DropDownList>
---------- -------------------------------------------------- ----------------------------------
DropDownCountry.Attributes.Add(onchange,LoseFocus(this));
----------------------------------------------------------------------------------------------
DropDownCountry.Attributes.Add("onchange", "LoseFocus(this)");
推荐答案
首先注意到的一个重要的事情就是你的登记事件在我看来两次了>
这里
DropDownCountry.Attributes.Add(onchange,LoseFocus(this ));
和
onchange =LoseFocus(this);在aspx中
从你的代码
我理解的是下拉丢失焦点你想要验证下拉列表请在下面执行相同的
的onblur = LoseFocus(本);使onblur而不是onchage。以下是更新javascript方法
功能LoseFocus(ddlElem){
ddlElem.blur();
var val = ddlElem.options [ddlElem.selectedIndex] .value;
if(val ==|| val ==选择)
alert(''错误'');
}
如果您需要更多帮助,请告诉我
First importtant thing to notice is your registering event onchage twice i
Here
DropDownCountry.Attributes.Add("onchange", "LoseFocus(this)");
and
onchange="LoseFocus(this);" in aspx
from your code what i understand is on dropdown lost focus you want validate dropdown please do it below for same
onblur="LoseFocus(this);" make onblur instead of onchage. and below is update javascript method
function LoseFocus(ddlElem) {
ddlElem.blur();
var val = ddlElem.options[ddlElem.selectedIndex].value;
if (val == "" || val == "Select")
alert(''Error'');
}
Please let me know if you need more help
这篇关于我对下拉验证有疑问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!