代码之家  ›  专栏  ›  技术社区  ›  Paul Knopf

删除所有没有id's x或x的输入

  •  1
  • Paul Knopf  · 技术社区  · 15 年前

    我的asp.net页面中有一个来自第三方的小部件。我不能使用嵌套表单,因此我正在临时更改asp.net的方法和操作以使用小部件。

    我有一个js方法我的widget方法调用中的元素

    function changeActionAndMethodOnFormAndSubmit(newAction, newMethod, newName) {
        var theForm = document.forms['aspnetForm'];
        if (!theForm) {
            theForm = document.Form1;
        }
        theForm.action = newAction;
        theForm.method = newMethod;
        theForm.name = newName;
        theForm.submit();
    }
    

    我想在提交表单之前删除页面上的所有输入元素,除了需要的once。我知道基于参数newname的元素的确切id,但是现在,假设我试图删除所有没有input.id为x或y的输入元素。

    1 回复  |  直到 15 年前
        1
  •  2
  •   Greg    15 年前

    这应该可以做到:

    $('input:not(#x,#y)', theform).remove()