在两个不同的代码片段中进行的更改--JQuery

问题描述 投票:0回答:1

这里有2个输入标签,其中“id1”标签可以修改但“id2”不能修改,所以当我在“id1”标签中进行任何更改时,“id2”标签中的值会发生变化,但“msg”中的值会发生变化class没有改变,因为“id2”标签的值在没有我们自己输入的情况下自动改变,我尝试了.changeinput propertychange但它不起作用。请求您的输入

<div class="wrap">
<input id= "id1"></input>
<input id = "id2" readonly></input>
<div class="msg"></div>
</div>
<script>
   $('#id1').bind('input propertychange', function() {
      $('#id2').val($(this).val());
   });
   $('#id2').bind('input propertychange ', function() {
      $('.msg').html($(this).val());
   });
</script>
jquery input autofill
1个回答
1
投票

触发事件..我无法想象为什么你需要这样做但是

$('#id1').bind('input', function() {
  $('#id2').val($(this).val()).trigger('input');
});
$('#id2').bind('input', function() {
  $('.msg').html($(this).val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrap">
<input id= "id1"></input>
<input id = "id2" readonly></input>
<div class="msg"></div>
</div>
© www.soinside.com 2019 - 2024. All rights reserved.