简体   繁体   中英

preventDefault() does not work in Firefox

Can anyone point out what is wrong with this code. This works in chrome but not in Firefox. I have updated my question to be more clear. Please have a look at the look below.Actaully, it is tinymce editor.When I click,the equation symbol in the toolbar,a span with class AMedit is automatically created.Now when the cursor is inside the equation,the enter key should not move the cursor to new line.My code works only in chrome but not in other browsers.You can check this in different browsers.

http://beyondthelogix.com/demos/editordemo/demo.html

tinyMCE.init({

theme : "advanced",
mode: "exact",
elements : "elm1",
setup : function(ed) {
ed.onInit.add(function(ed, evt) {
    tinymce.dom.Event.add(ed.getDoc(), 'keydown', function(e) {
        var existing = tinyMCE.get('elm1').getElement(e);
        var code = (e.keyCode ? e.keyCode : e.which);
        var spans = tinyMCE.activeEditor.getBody().getElementsByTagName("span");
        if (spans.length > 0)
        {
           for (var i = 0; i < spans.length; i++)
           {
              if (spans[i].getAttribute("class") === "AMedit")
              {
                 if (code === 13)
                 {

        (e.preventDefault) ? e.preventDefault() : e.returnValue = false;
         }
              }
           }
        }
    });
  });
},

When I use alert, I get it in firefox but e.preventDefault() does not work.

 $("#button").click(function (e) {
    e.preventDefault();

Chrome initializes the event but Firefox doesn't. Use this and it will work in Firefox and Chrome.

Don't put 100 preventDefault(); . Put where is needed.

Example:

$(".button").click(function (e) {
    e.preventDefault();
    $(this).fadeOut(250, function () {
        $(this).closest('td').children('.hiddenDiv').show().fadeIn();
    });
});

Hope it helped.

This: (e.preventDefault) ? e.preventDefault() : e.returnValue = false; (e.preventDefault) ? e.preventDefault() : e.returnValue = false; it seems you are trying to access a property preventDefault instead of call method preventDefault()

尝试返回false,应该可以在所有浏览器上使用。

return false;

try tu use evt instead of e to use the preventDEfault.

evt.preventDefault()

I think you are calling a variable or aprameter that doesn't exists. Doy you see anything in the console?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM