jQuery - IE gives [object Object] error when displaying dialogs

筅森魡賤 提交于 2019-11-28 11:50:10

问题



I'm making a page where a jQuery dialog comes up with some inputs and later javascript displays them. This works fine in:

  • Chrome 31
  • Opera 18
  • Safari 5 (This is really old because I'm using safari for windows)

However, it does not work in Internet Explorer 7-11, or Firefox 26.

DEMO: http://bit.ly/1chhvBN

Error in IE 11:

Any Ideas? Thank you in advance.


回答1:


Do not use href attributes to bind event handlers to elements. You have jQuery, use that to bind the events.

<div id="favorites">
    <a href="#" class="add">+</a>
</div>

Then, simply do:

$('#favorites a').click(function(e){
    e.preventDefault();
    $( '#dialog' ).dialog({width: 850, height: 300});
});

Do the same with the addToFavorites button.

<a href="#" class="addToFavorites button" style="width: 150px;">Add to My Favorites</a>

Then do:

$('.addToFavorites').click(function(e){
    e.preventDefault();
    addToFavorites();
});

Here's a demo: http://jsfiddle.net/aRpcL/3/




回答2:


Use onclick instead of href for opening the dialog.

<a onclick="javascript:$( '#dialog' ).dialog({width: 850, height: 300});" class="add">+</a>

Note: Try to avoid inline scripting, move the JS code to some function and call it.



来源:https://stackoverflow.com/questions/20845695/jquery-ie-gives-object-object-error-when-displaying-dialogs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!