input 框定时更换 placeholder 文案

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>定时更换内容</title>
  <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>

<body>

  <div id="content">
    这是初始内容。
  </div>
  <div>
    <input type="text" placeholder="默认提示文案" id="inputId">
  </div>
  <button id="start">开始</button>
  <button id="pause">暂停</button>

  <script>
    $(document).ready(function () {
      var messages = ["例:贴片电阻", "例:HS10 R05J", "例:备选电阻啊"];
      var index = 0;
      var timer;
      /**
       * 定时切换文案
       */
      function startSwitch() {
        if (timer === undefined) {
          timer = setInterval(function () {
            //文本内容
            $('#content').fadeOut(function () {
              $(this).text(messages[index]).fadeIn();
            });
            //input 内容
            $('#inputId').fadeIn(function () {
              $(this).attr('placeholder', messages[index]).fadeIn();
            })

            index = (index + 1) % messages.length;
          }, 2000); // 每2秒更换一次内容
        }
      }
      /**
       * 暂停切换文案
       */
      function blurSwitch() {
        clearInterval(timer);
        timer = undefined;
      }

      $('#start').click(function () {
        startSwitch();
      });

      $('#pause').click(function () {
        blurSwitch()
      });
      startSwitch();
      //input 获取焦点事件
      $('#inputId').focusin(function () {
        console.log('---------')
        blurSwitch()
        $(this).attr('placeholder', "默认提示文案").fadeIn();
      }).blur(function () {
        console.log('eeeeeeee')
        startSwitch();
      })
    });
  </script>

</body>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wbandzlhgod

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值