Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util.on多事件处理 #1888

Closed
4 tasks done
hitabullet opened this issue May 10, 2024 · 3 comments
Closed
4 tasks done

util.on多事件处理 #1888

hitabullet opened this issue May 10, 2024 · 3 comments
Labels
wontfix 不做修复与处理,或无法解决

Comments

@hitabullet
Copy link

议题条件

  • 我确认已查看官方使用文档:https://layui.dev ,但没有找到相关解决方案。
  • 我确认已在 Issues 中搜索过类似的问题,但没有找到相关解决方案。
  • 我已仔细阅读: 🍀 Layui Issue 贡献指南

议题类型

功能请求

使用版本

2.9.9

问题描述

util.on绑定多个事件

业务代码

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Demo</title>
  <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
  <link href="//unpkg.com/[email protected]/dist/css/layui.css" rel="stylesheet">
</head>
<body class="layui-padding-3">

<div class="layui-btn-container">
  <button class="layui-btn" lay-active="e3">事件 3</button>
</div>
  
<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script src="//unpkg.com/[email protected]/dist/layui.js"></script>
<script>
layui.use('util', function(){
  var util = layui.util;
   // 自定义:触发事件的元素属性名、触发事件的方式
   util.on('lay-active', {
      e3: {
          mouseenter: layui.throttle(function(othis) {
              console.log(this);
              tipsIndex = layer.tips(othis.html(), this, { time: 0 });
          }, 3000),
          mouseleave: function(othis) {
              if (tipsIndex !== null) {
                  layer.close(tipsIndex); // 鼠标移出时关闭layer.tips
                  tipsIndex = null; // 重置索引
              }
          }
      }
  }, {
      trigger: ['mouseenter', 'mouseleave'] // 鼠标移入和移出时触发事件
  });
});
</script>


</body>
</html>

截图补充

错误

浏览器

124.0.6367.119

演示地址

No response

友好承诺

  • 我承诺将本着相互尊重、理解和友善的态度进行交流,共同维护 Layui 良好的社区氛围。
@sentsim sentsim added the wontfix 不做修复与处理,或无法解决 label May 10, 2024
@sentsim
Copy link
Member

sentsim commented May 10, 2024

现有功能可满足需求,不同事件建议分开书写。

@hitabullet
Copy link
Author

现有可能可满足需求,不同事件建议分开书写。

作者大大,请问要怎么写,我分开写是覆盖掉之前的 util.on(
'lay-active',
{
e3: layui.throttle(function (othis) {
console.log("22");
}, 3000),
},
{
trigger: 'mouseenter',
}
);

    util.on('lay-active',
      {
        e3: function (othis) {
          if (tipsIndex !== null) {
            console.log('11');
          }
        },
      },
      {
        trigger: 'mouseleave',
      }

@Sight-wcg Sight-wcg closed this as not planned Won't fix, can't repro, duplicate, stale May 17, 2024
@Sight-wcg
Copy link
Collaborator

这种需求建议用 jQuery 的写法

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix 不做修复与处理,或无法解决
Projects
None yet
Development

No branches or pull requests

3 participants