检测,自动将输入Id更改为当前Id名称

Detect & Automatically Change Input Id to current Id name?

本文关键字:Id 名称 检测 输入      更新时间:2023-09-26

我看过关于检测输入id值的更改的教程,但是如果要更改输入id名称,是否有一个快速的代码片段或代码来更新它?我是新手,我做了一些研究,发现了这个代码

setInterval(function() { ObserveInputValue($('#input_id').val()); }, 100);

是否有可能检测输入id的名称是否更改,然后自动更新和更改变量?

示例$('#myname').val('name').change();如果输入id更改为nameofperson,什么代码会自动检测到并将输入id name更改为nameofperson?

显示input的id更改时间

var original="test";
setInterval(function() { // the will listen the id change or not
  var current = $('input').attr('id');
  if(original != current) //matching the id with previous id
    {
       original = current;
      console.log('id was changed your new id= '+current)
      }
 }, 100);
var count =0;
$('button').click(function(){
  $('input').attr('id','change'+count);//each time you click id was changed.
  count++;
  })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="test" class="changing">
<button>changeId</button>