Asp.net jQuery服务器端按钮
我有一个页面(ASP.NET 3.5),其中有许多按钮,有些是保存按钮,有些不是。我必须是泛型的,即不能按ID调用单个控件。我的保存按钮可能具有UserSubmitBehavior=true属性。在单击事件处理程序中,我需要区分我按下的按钮类型,因此:Asp.net jQuery服务器端按钮,asp.net,jquery,Asp.net,Jquery,我有一个页面(ASP.NET 3.5),其中有许多按钮,有些是保存按钮,有些不是。我必须是泛型的,即不能按ID调用单个控件。我的保存按钮可能具有UserSubmitBehavior=true属性。在单击事件处理程序中,我需要区分我按下的按钮类型,因此: $('input[type=submit]').bind('click', function(e) { //need to know how to set up this condition if (this.type = "su
$('input[type=submit]').bind('click', function(e)
{
//need to know how to set up this condition
if (this.type = "submit")
{
//do something here
}
else
{
//do something else
}
});
我该怎么做呢?您可以使用css类:
<asp:Button CssClass="SubmitButton" ... />
这对您有用吗?如果我理解正确,您有多种类型的按钮,包括常规按钮和提交按钮。您可以在一个函数中完成此操作,如下所示:
$('input[type=submit], input[type=button]').bind('click', function(e)
{
if ($(this).attr('type') == "submit")
{
//do something here
}
else
{
//do something else
}
});
您还可以通过以下方式将其分解为更具可读性的内容:
$('input[type=button]').bind('click', function(e){
//do button stuff here
});
$('input[type=submit]').bind('click', function(e){
//do submit stuff here
});
就个人而言,我更喜欢第二种方法。我在需要识别GridView控件中的标签或文本框的时候做了这个小把戏。我要做的是添加一个自定义属性来帮助我在页面上识别它们。例如:
<asp:Label ID="lblSpecial" runat="server" Text="Whatever" MyCustomeAttr="SpecialLabel">
<asp:Label ID="lblSpecial2" runat="server" Text="Whatever" MyCustomeAttr="SpecialLabel2">
是的,但我无法区分页面上的非提交按钮和文本框谢谢回复。是的,我更喜欢第二个,所以我很快就会试试。我认为,如果我将UseSubmitBehavior=false设置为“button”类型,而不是“submit”,那么这不会破坏XHTML遵从性吗?
<asp:Label ID="lblSpecial" runat="server" Text="Whatever" MyCustomeAttr="SpecialLabel">
<asp:Label ID="lblSpecial2" runat="server" Text="Whatever" MyCustomeAttr="SpecialLabel2">
$("span[id$='_lblSpecial2'][MyCustomeAttr='SpecialLabel2']");