js的话利用input的onchange事件

而jquery的话利用change()函数,代码如下:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <script src="../jquery-1.10.2.min.js" type="text/javascript" charset="utf-8"></script>
    </head>
    <body>
        <div data-default="">
            cc
        </div>
        <input type="text" name="" id="" value="" />
        <script type="text/javascript">
            $('input[type="text"]').change(function(){
                $('div').attr({'data-default': $(this).val()});
                
                $('div').text($('div').attr('data-default'));
            });
            
        </script>
    </body>
</html>

 

相关文章:

  • 2021-11-26
  • 2022-12-23
  • 2022-03-09
  • 2022-12-23
  • 2021-12-13
  • 2022-12-23
猜你喜欢
  • 2022-01-24
  • 2022-12-23
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
相关资源
相似解决方案