JQuery的如果某些textboxe的都是空的,禁用按钮 [英] JQuery if certain textboxe's are empty, disable button
问题描述
我见过的人禁用按钮,如果文本框为空很多例子,但我没有找到任何这将禁用只有某些文本框按钮。我是新来的jQuery和我知道它是假codeD,但你可以得到的想法。其中jQuery函数我必须调用,使其不断检查?我怎么可以用一个或语句if子句中,以确定是否任何文本字段为空?
如果($('#txtEvent)。val.length === 0 || $(#txtID)。val.length === 0)
{
$('#btnSave)ATTR(已禁用,已禁用)。
}
其他
{
$('#btnSave)ATTR(已启用,已启用);
}
窗体控件
< ASP:文本框ID =txtEvent=服务器>< / ASP:文本框>
< ASP:文本框ID =txtID=服务器>< / ASP:文本框>
< ASP:按钮的ID =btnSave=服务器,文本=保存并下一步/>
您可以做两种不同的方式:
如果(!$(#txtEvent)。VAL()){//不确定会产生假
//调用方法! .VAL()不.VAL
$(#btnSave)ATTR(已禁用,已禁用)。
} 其他 {
$(#btnSave)ATTR(已启用,已启用)。
}
或者
如果($(#txtEvent)长度GT; 0){
$(#btnSave)ATTR(已禁用,已禁用)。
} 其他 {
$(#btnSave)ATTR(已启用,已启用)。
}
如果您希望用不断磨合,包装在:
$(#txtEvent)上(变,函数(){// code})。
//使用onchange事件将触发code每当txtbox变化。
//你也可以使用的onblur如果你想让它触发后的txtbox失去焦点
请注意,你必须将它们转换为正确的ASP code!这仅仅是一个后勤的答案。
I've seen plenty examples of people disabling buttons if textboxes are empty but I haven't found any which will disable a button for only certain textboxes. I'm new to Jquery and I know it is pseudo coded but you can get the idea. Which Jquery function do I have to call so that it is constantly checking? And how can I use an or statement in the if clause to determine if any textbox field is empty?
if( $('#txtEvent').val.length === 0 || $("#txtID").val.length === 0)
{
$('#btnSave').attr("disabled", "disabled");
}
else
{
$('#btnSave').attr("enabled", "enabled");
}
Form Controls
<asp:TextBox ID="txtEvent" runat="server"></asp:TextBox>
< asp:TextBox ID="txtID" runat="server"></asp:TextBox>
<asp:Button ID="btnSave" runat="server"" Text="Save and Next" />
You can do it two different ways:
if (!$("#txtEvent").val()) { //undefined will yield false
//call a method! .val() not .val
$("#btnSave").attr("disabled", "disabled");
} else {
$("#btnSave").attr("enabled", "enabled");
}
Or:
if ($("#txtEvent").length > 0) {
$("#btnSave").attr("disabled", "disabled");
} else {
$("#btnSave").attr("enabled", "enabled");
}
If you want these constantly running, wrap them in:
$("#txtEvent").on("change", function() { //code });
//using the onchange event will trigger the code whenever the txtbox changes.
//you can also use onblur if you want it to trigger AFTER the txtbox loses focus
Please note you'll have to convert these into proper asp code! This is simply a logistical answer.
这篇关于JQuery的如果某些textboxe的都是空的,禁用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!