首页 \ 问答 \ 过滤器是否保留列表排序?(Does filter preserve list ordering?)

过滤器是否保留列表排序?(Does filter preserve list ordering?)

假设您在列表中调用“过滤器”函数,并使用它来查找所有满足特定属性的元素。 输出列表中的元素是否保证与它们​​在输入列表中的顺序相同?


Say you call the "filter" function on a list, and you use this to find all elements that satisfy a certain property. Are the elements in the output list guaranteed to be in the same order that they were in the input list?


原文:https://stackoverflow.com/questions/26566663
更新时间:2023-03-19 22:03

最满意答案

你的按钮......

<button name="Login" type="button"  onclick="submitform();">Register</button>

您不需要任何带有jQuery的内联JavaScript。 而你肯定不需要jQuery Validate插件的onclick处理程序。

将您的type更改为submit并删除内联点击处理程序...

<button name="Login" type="submit">Register</button>

你也不能把一个return false放到你的DOM就绪处理程序中......

$(document).ready(function () {

    $('#formreg').validate({
        // your rules
    });

    // return false;  // <- REMOVE THIS LINE

});

工作演示: http//jsfiddle.net/M9Y6L/1/


Your button...

<button name="Login" type="button"  onclick="submitform();">Register</button>

You do not need any inline JavaScript with jQuery. And you certainly don't need an onclick handler for the jQuery Validate plugin.

Change your type into submit and remove the inline click handler...

<button name="Login" type="submit">Register</button>

You also cannot put a return false into your DOM ready handler...

$(document).ready(function () {

    $('#formreg').validate({
        // your rules
    });

    // return false;  // <- REMOVE THIS LINE

});

Working DEMO: http://jsfiddle.net/M9Y6L/1/

相关问答

更多
  • 您的代码因以下原因而中断... 1)您错误地将success选项放在messages选项中。 success选项是messages的兄弟 ,而不是孩子。 messages: { username: "Please enter a valid email address", password: { required: "Please provide a password", minlength: "Your password must be at least 5 ...
  • 你的按钮...... 您不需要任何带有jQuery的内联JavaScript。 而你肯定不需要jQuery Validate插件的onclick处理程序。 将您的type更改为submit并删除内联点击处理程序... 你也不能把一个return ...
  • 你的代码: if($('#cartForm').length > 0) { $('#proceedCheckout').on('click', function (event) { console.log('HSA'); $('#changeCountry').validate({ // <-- move out of here errorClass: 'alert-error' }); event.preven ...
  • jquery-validate要求每个元素都有唯一的名称。 所以将for循环索引放入名称中。
    phoneUS方法在additional-methods.js定义。 如果你包含这个文件(并确保你的输入有一个type='text' ),它应该可以正常工作: JavaScript的: $("#signupForm").validate({ rules: { phone: 'phoneUS' }, messages: { phone: 'Enter a valid phone number' }, submitHandler: func ...
  • 这样的事可能吗? HTML -
    Submit

    JS - var user = {} $('#submit').click(function(){ // validating form if(!$('#name').val()) { $('#er ...
  • 我在表单上使用.valid()来检查有效性,似乎已经解决了问题。 感谢@StephenMuecke的建议。 我的新jQuery看起来像这样 @section Scripts { @Scripts.Render("~/bundles/jqueryval")