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

一开始进入,用鼠标全选并删除,onchange不触发 (作者能不能加入oninput监听?) #1749

Closed
herotony008 opened this issue Oct 11, 2018 · 10 comments

Comments

@herotony008
Copy link

编辑器创建并赋值内容,当用鼠标全选,并且鼠标失去焦点(是在编辑器框架外失去焦点),此时按DEL键删除, 不会触发onchange事件,(目前编辑器里面显示的内容已经为空)。但是 如果失去焦点是在编辑器里面,则会触发

@herotony008
Copy link
Author

一开始就用鼠标左键选中全部,并在编辑器外松开鼠标左键,点删除,才能复现这个问题。(不要在一开始,点击后再去操作,这时候不能复现这个问题)

@herotony008 herotony008 changed the title 一开始进入,用鼠标全选并删除,onchange不触发 一开始进入,用鼠标全选并删除,onchange不触发 (作者能不能加入oninput监听?) Oct 11, 2018
@lqwzjay
Copy link

lqwzjay commented Oct 18, 2018

问题解决了吗,我也遇到了同样的问题,第一次进去鼠标选中后 键盘删除,没有触发onchnage事件

@eeeeeeeason
Copy link

+1

@eeeeeeeason
Copy link

我认为原因是点击事件由mousedown,mouseup都在元素内时触发,但若第一次鼠标抬起时在元素外,认为没有触发点击事件,点击事件会开始onchange,我们改第一次down为人为触发click即可
@lqwzjay 处理偏方如下

mousedown触发编辑框里面p标签click()函数、

@herotony008
Copy link
Author

问题解决了吗,我也遇到了同样的问题,第一次进去鼠标选中后键盘删除,没有触发onchnage事件

你可以试下如下方式:

var E = window.wangEditor
var editor = new E('#div1')
editor.customConfig.onchange = function (html) {
// html 即变化之后的内容
console.log(html)
}
editor.create()

document.getElementById('btn1').addEventListener('input', function () {
    // 如果未配置 editor.customConfig.onchange,则 editor.change 为 undefined
    //editor.change && editor.change()
     var content = editor.txt.html()

      if(content =='' || content =='<p><br></p>'){
        editor.customConfig.onchange();
      }
   
})

@qilvnuanqingyou
Copy link

qilvnuanqingyou commented Nov 5, 2018

@eeeeeeeason 感谢大神,按你的思路解决了

@nanaismylove
Copy link

这个问题在react 怎么解决?

@pollux2015
Copy link

@eeeeeeeason 确实可以

@yohugSu
Copy link

yohugSu commented Jun 26, 2019

我认为原因是点击事件由mousedown,mouseup都在元素内时触发,但若第一次鼠标抬起时在元素外,认为没有触发点击事件,点击事件会开始onchange,我们改第一次down为人为触发click即可
@lqwzjay 处理偏方如下

mousedown触发编辑框里面p标签click()函数、

大神,可以具体说说怎么实现吗?mousedown事件要绑定在p标签吗?可否展示个代码?

@yohugSu
Copy link

yohugSu commented Jun 26, 2019

触发编辑框里面p标签click()函数

如何触发p标签的click函数这个可以给个代码吗?不是很明白

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants