Javascript 如何从表单中的所有输入复制自定义属性,然后重新分配?

Javascript 如何从表单中的所有输入复制自定义属性,然后重新分配?,javascript,jquery,Javascript,Jquery,我有一个表格,有很多输入(文本、选择框、提交等)。。表单上有两个按钮,单击第一个按钮时,我希望从所有输入复制自定义属性,如果单击第二个按钮,我希望在自定义属性为空(=“”)时重新分配这些属性 我现在拥有的: 一个表单(#myForm),有几十个输入 如果输入没有名为的特定类,则取消指定自定义属性的函数。dontcheck $(':input','#myForm') .not(':button, :submit, :reset, :hidden, .dontcheck') .attr("cust

我有一个表格,有很多输入(文本、选择框、提交等)。。表单上有两个按钮,单击第一个按钮时,我希望从所有输入复制自定义属性,如果单击第二个按钮,我希望在自定义属性为空(=“”)时重新分配这些属性

我现在拥有的:

  • 一个表单(
    #myForm
    ),有几十个
    输入
  • 如果输入没有名为
    的特定类,则取消指定自定义属性的函数。dontcheck

    $(':input','#myForm')
    .not(':button, :submit, :reset, :hidden, .dontcheck')
    .attr("customAttribute","");
    
因此,当单击第一个按钮时,我应该复制所有输入“
customAttribute
,如果没有
类,则清除
customAttribute
。我有干净的部分,但我不知道如何复制,然后将
customAttribute
分配回具有自己唯一
id
的每个输入


我是JQuery world的新手,任何建议或帮助都将不胜感激。

感谢您接受我的回答@用户2783091,这超出了我的要求。。我也学到了一些东西。
  var   customAttrList;

 function deleteCustomAttr(){   var elementToDeleteAttr = $(':input','#myForm')
  .not(':button, :submit, :reset, :hidden, .dontcheck');

 customAttrList = {};

  $.each(elementToDeleteAttr, function(index, item){
         customAttrList [item.id] = $(item).attr("customAttribute");//copy attributes and save by Id
         $(item).attr("customAttribute", "");
  });


}
 function returnAttrBack(){
       var elementToBackAttr = $(':input','#myForm')
  .not(':button, :submit, :reset, :hidden, .dontcheck');

 $.each(elementToBackAttr , function(index, item){
         $(item).attr("customAttribute", customAttrList[item.id]);//get attribute by Id

  });

 }