单击鼠标,然后输入按钮(SUBMIT FORM with mouse clicking and enter button)
我通过MOUSE CLICK和ENTER提交表格。
Ajax Call正在检查是否有我已经在DATABASE中的任何指定..如果没有,用户可以提交表单否则SUBMIT按钮将DISABLE
JQUERY
function check_designation(e){ text = $('#req1').val(); data = "data=" + text; text_length = text.length if(text_length == 0) { $('#result_span').html(''); } if(text_length > 3 ){ $.ajax({ url: "designation_ajax.php", type: "POST", data: data, cache: false, success: function (response) { if ($.trim(response) == "access") { $("#result_span").html('<div class="green">' + text + ' is available '+'</div>'); $('#create_desg').removeAttr('disabled'); } else if ($.trim(response) == "no access") { $("#result_span").html('<div class="red">' + text + ' is already in use'+'</div>'); $('#create_desg').attr('disabled','disabled'); } else { alert('Sorry, unexpected error. Please try again later.'); } } }); } else{ $("#result_span").html(''); } return true; }
HTML表格
<form id="formID" class="formular" method="POST" action="" onsubmit="formSubmit()" > <fieldset> <legend>Create Desination</legend> <label> Designation<br clear="all" /> <input autocomplete="off" onkeyup="check_designation(event)" value="" class="validate[required,minSize[4]] text-input float_left" type="text" name="name" id="req1" /> <span id="result_span"></span> </label> <br clear="all" /> <input id="create_desg" value="Submit" type="button" /> </fieldset> </form>
问题::::
现在发生的事情DISABLE按钮不是解决方案...如果表中已有DESIGNATION ..提交按钮将禁用但是按ENTER将提交,我不想重新加载页面。 当我按下ENTER时,AJAX不起作用
I am Submiting form through MOUSE CLICK and ENTER too.
Ajax Call is checking is there any designation which i already in DATABASE.. If not, user can submit form otherwise SUBMIT button will DISABLE
JQUERY
function check_designation(e){ text = $('#req1').val(); data = "data=" + text; text_length = text.length if(text_length == 0) { $('#result_span').html(''); } if(text_length > 3 ){ $.ajax({ url: "designation_ajax.php", type: "POST", data: data, cache: false, success: function (response) { if ($.trim(response) == "access") { $("#result_span").html('<div class="green">' + text + ' is available '+'</div>'); $('#create_desg').removeAttr('disabled'); } else if ($.trim(response) == "no access") { $("#result_span").html('<div class="red">' + text + ' is already in use'+'</div>'); $('#create_desg').attr('disabled','disabled'); } else { alert('Sorry, unexpected error. Please try again later.'); } } }); } else{ $("#result_span").html(''); } return true; }
HTML FORM
<form id="formID" class="formular" method="POST" action="" onsubmit="formSubmit()" > <fieldset> <legend>Create Desination</legend> <label> Designation<br clear="all" /> <input autocomplete="off" onkeyup="check_designation(event)" value="" class="validate[required,minSize[4]] text-input float_left" type="text" name="name" id="req1" /> <span id="result_span"></span> </label> <br clear="all" /> <input id="create_desg" value="Submit" type="button" /> </fieldset> </form>
PROBLEM::::
Now what happen DISABLE button is not a solution... if there is already a DESIGNATION in a table.. submit button will disable but By ENTER it will submitted and i dont want to reload the page. and AJAX is not working when i PRESS ENTER
原文:https://stackoverflow.com/questions/10145152
最满意答案
这应该可以解决问题,(编辑:请参阅下面的不使用Distinct的版本。)
(from parents in collection from all in collection where parents.ValidFlag == 1 && parents.ParentId == null && all.ValidFlag == 1 && (all.ParentId == null || all.ParentId == parents.Id) select all).Distinct();
上面的代码应该有希望生成一些与它本身在SQL中看起来非常相似的东西,可能除了distinct之外可能会导致它返回实际需要在客户端上过滤的更多数据。 如果有大量数据,可能会成为一个问题,主要是如果有很多父母,因为它会返回重复的那些)
这是在没有明确调用的情况下重新编写的查询
from parents in collection // parents is only used to decide which children to get from all in collection // this is where we will actually grab our data from where parents.ValidFlag == 1 && // only include parents that are valid parents.ParentId == null && // and that are parents all.ValidFlag == 1 && // only include entries that are valid ( (all.ParentId == null && all.Id == parents.Id) || // If entry is a parent, match with itself to limit returns to 1 all.ParentId == parents.Id // otherwise, parentid should match one of the valid parents. ) select all
This should do the trick, (edit: see below for version that doesn't use Distinct.)
(from parents in collection from all in collection where parents.ValidFlag == 1 && parents.ParentId == null && all.ValidFlag == 1 && (all.ParentId == null || all.ParentId == parents.Id) select all).Distinct();
The above code should hopefully generate something quite similar to what it itself looks like in SQL, maybe with the exception of the distinct which might cause it to return more data that is actually needed to be filtered on the client. Something that might become an issue if there's a lot data, chiefly if there's a lot of parents because it will return duplicates of those)
Here is the query reworked without the distinct call
from parents in collection // parents is only used to decide which children to get from all in collection // this is where we will actually grab our data from where parents.ValidFlag == 1 && // only include parents that are valid parents.ParentId == null && // and that are parents all.ValidFlag == 1 && // only include entries that are valid ( (all.ParentId == null && all.Id == parents.Id) || // If entry is a parent, match with itself to limit returns to 1 all.ParentId == parents.Id // otherwise, parentid should match one of the valid parents. ) select all
相关问答
更多-
表的Angular指令作为父级,theader和tbody作为子级(Angular directive for table as parent and theader and tbody as child)[2023-11-21]
一种可能仍然提供所需“一个模板适用于所有”目标的不同方法是编写html模板文件,并在通过声明ng-include使用表时引用它。 与旧的服务器端包含类似,它提供了一种方法,可以随时随地注入一个html块,而无需指令的所有开销。 我们实际上已经退出了制定如此多的指令,并且当指令中没有任何工作要做时,我们开始使用包含更多指令。 有关ngInclude的Angular文档 For the ones who might come here my solution has to add to the directiv ... -
您需要包含这样的相关实体: SniffDAO dao = new SniffDAO(); var test = dao.SniffResults.Include(x=>x.address).Where(sr.fk_scan == 3); foreach (var one in test) { Console.WriteLine(one.pk_SniffResult); Console.WriteLine(one.address); ...
-
这是为您提供子元素的查询(假设只有一个具有指定标签的child元素): var childElement = rootNode.Descendants("child") .Single(e=>e.Attribute("label").Value == "child1"); 如果您有多个带有label="child1" child元素但这些元素位于不同的parent元素下,则可以使用相同的方法首先获取parent元素,然后获取child元素。 有了上述内 ...
-
试试吧 --Variable to hold input value DECLARE @inputSourceID INT = 1; --Recursive CTE that finds all children of input SourceID WITH MyCTE AS ( SELECT SourceID, SourceParentID FROM table1 WHERE SourceID = @inputSourceID UNION ALL SELECT table1.Sourc ...
-
这应该可以解决问题,(编辑:请参阅下面的不使用Distinct的版本。) (from parents in collection from all in collection where parents.ValidFlag == 1 && parents.ParentId == null && all.ValidFlag == 1 && (all.ParentId == null || all.ParentId == parents.Id) select all).Disti ...
-
这是你可以做的: var lookup = dt .AsEnumerable() .ToLookup(p => p.Field
("ParentId")); 现在,如果您想要根元素执行此操作: var roots = lookup[null]; 如果你想要任何孩子,给定parentId ,你这样做: var children = lookup[parentId]; 简单,对吧? 这是基于您的编辑的一些代码。 我使用匿名类型定义了项目列表: var it ... -
LINQ基于孙子标准返回具有子集子集的父级(LINQ return parent with subset of children based on grandchild criteria)[2021-09-12]
就像我的兄弟@DeclanMcD在链接问题中一样 ,我不得不求助于显式过滤数据。 我觉得这个解决方案可能会更清洁,但我仍然不喜欢它: // What I want is the allSites array but with the terminals filtered. ListtoReturn = new List (allSites); foreach (Site s in toReturn) { // Look through every Terminal / ... -
这里是一个关于如何使用LINQ来做的例子。 首先是数据表。 我假设顶级项目的父ID为0。 var dataTable = new DataTable(); dataTable.Columns.Add("Id", typeof(Int32)); dataTable.Columns.Add("ParentId", typeof(Int32)); dataTable.Columns.Add("Name", typeof(String)); dataTable.Rows.Add(new Object[] { 1, ...
-
也许这个: public static IQueryable
ContainsChild(this IQueryable qry, int[] childrenIDs) { return qry.Where(p => p.Children.Any(c => childrenIDs.Contains(c.AnotherID))); } 编辑 只是为了娱乐另一种方式应该给出相同的结果: public static IQueryable Contain ... -
在linq中使用左连接,如下所示,它没有经过测试,但它的作用是它留下了外部连接fakeSet和fakeSet2。 var rows = from a in crmLinqContext.fakeSet join b in crmLinqContext.fake2Set on a.fake2.Id equals b.Id into subset from b in subset.DefaultIfEmpty() join c in crmLinqContext.fake3Set ...