【问题标题】:jquery mouseenter is not working on imgjquery mouseenter 不适用于 img
【发布时间】:2013-07-11 16:33:49
【问题描述】:

我正在尝试将图像拖到 jquery 文本编辑器 (jqte) 中,然后在编辑器中调整它的大小。由于调整大小功能仅在 Firefox 中有效。所以我想在 mouseenter 上提供 W 和 H 文本框来改变大小。但是 mouseenter 对 img 元素不起作用。

     <div class="jqte_editor" contenteditable="true"><pre style="font-family:consolas;">
      <br>
        &nbsp;&nbsp;&nbsp;&nbsp;
         <img style="border-left-width: 1px; border-left-style:   solid; border-left-color: rgb(255, 255, 255); border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(255, 255, 255);" src="http://localhost:65380/Articles/ArticleImageStore/cf82c9c8-3ea0-4c7f- 9272-7b2fd48a9eed/79825f3f-965f-4e34-ad45-3fa7430e6837.JPEG" width="64" height="64" id="img6">         
     </pre>
     <p><br></p>
     <pre style="font-family:consolas;">&nbsp;&nbsp;&nbsp;</pre>  <p></p>                         
     </div> 

jquery代码sn-p

         $('.jqte_editor img').on('mouseenter', function() { 
             alert("hello");
             $(this).before("<div style='position:absolute'><input type='textbox'></input></div>"); 
         });

【问题讨论】:

  • 你能用小提琴重现这个问题吗?
  • jsfiddle.net/ZJm2X@techfoobar
  • 移除 $(document).ready(...); 包装器,因为 jsfiddle 已经在页面加载时执行您的代码。检查这个:jsfiddle.net/ZJm2X/2
  • JQTE 内部没有任何工作..
  • 你查看我发布的小提琴链接了吗?

标签: javascript jquery html jqte


【解决方案1】:

您的代码运行良好:http://jsfiddle.net/ANnH2/

如果您没有将代码包装在 .ready 函数中,请检查一次:

$(document).ready(function(){
    $('.jqte_editor img').on('mouseenter', function() {
        alert("hello");
        $(this).before("<div style='position:absolute'><input type='textbox'></input></div>"); 
    });

});

【讨论】:

  • jqte 是否有任何额外的东西可以阻止我需要的功能
【解决方案2】:

您的代码正在运行here

要么您没有包含必需的jQuery library,此link 显示了jQuery 的工作原理,要么您没有将事件绑定放入document.ready

添加 jQuery

<script src="http://code.jquery.com/jquery-latest.min.js" 
               type="text/javascript"></script>

document.ready 中的绑定事件

$(document).ready(function(){
    $('.jqte_editor img').on('mouseenter', function() { alert("hello"); $(this).before("<div style='position:absolute'><input type='textbox'></input></div>"); });
});

【讨论】:

  • 你错过了结束)最后,检查更新,jsfiddle.net/ZJm2X/1
  • Missing the closing ) at to close $(document).ready(function() {...})
  • 对不起,我在小提琴上错过了这个,但它在页面上。但仍然无法正常工作。
  • Jquery 在母版页上
  • 并检查 jquery 链接列出的资源
猜你喜欢
  • 1970-01-01
  • 2018-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-20
  • 2011-08-16
  • 2012-10-20
相关资源
最近更新 更多