Tag: javascript events

e.target和e.relatedTarget有什么区别?

on e.target on使用jQuery时on会给我一个触发均匀的元素,但是当使用Bootstrap模式时,我通过e.relatedTarget访问触发元素。 我想了解他们的不同之处。

如何在执行新的动画之前停止Jquery中的所有先前动画?

我只是在尝试使用JQuery。 我有一个图像,当mouseOver()出现时淡入另一个图像并在mouseOut()上淡化 它的效果很好,除非你将鼠标一次又一次地移动到链接上,比如5次,图像反复淡入淡出,5次,而你只是坐在那里等待它克服这种疯狂的行为。 为了阻止这种行为,我尝试使用一个标志并仅在它尚未动画时启动动画,但是,猜猜是什么? 例如,如果我有4个这样的按钮,并且在每个按钮鼠标hover上我正在淡化在不同的图像中,该动画将被忽略,因为该标志是假的。 那么有没有办法在执行新动画之前停止所有以前的动画? 我在谈论JQuery中正常的fadeIn()和slideDown()函数 编辑:从链接添加代码。 Tick JavaScript的 function mouseOverOut(t) { if(t) { $(‘.img1’).fadeIn(); $(‘.img2’).fadeOut(); } else { $(‘.img1’).fadeOut(); $(‘.img2’).fadeIn(); } }

检测url上的更改

我需要一些东西来检测url上的更改,但页面不会回发,它会动态更改,只添加html中的div,所以URL页面是这样的 HTTP://www.examplepage/conversations/44455 当我点击页面的另一部分时,它就是 HTTP://www.examplepage/conversations/44874 它不仅在最后变化,而且像这样 HTTP://www.examplepage/settings 没有回复和重新加载JavaScript所以我的问题是,有没有办法检测这些变化? 和事件监听器但如何? 我搜索并且每个人都说哈希事件,但是在任何哈希之后我没有任何值,所以它不起作用 编辑 只是为了记录,我没有页面的代码,也没有访问权限,我会更好地解释,我正在做一个后台谷歌扩展,我只是添加了一个幻灯片到现有页面,这个页面改变了我的方式我解释的方式以上。 url会像每个页面一样发生变化,但是它们会更改html中的div,以便页面不必再次收取所有内容

为什么jQuery有时会覆盖window.onbeforeunload?

我有jQuery(1.6.x)的奇怪问题。 我在我的页面上有这个简单的电话: window.onbeforeunload = function() { return ‘Are you sure ?’; }; 但它不起作用,因为正如我发现的那样,jQuery会覆盖window.onbeforeunload的内容。 在JS控制台中,我可以看到window.onbeforeunload包含一段jQuery代码: function( e ) { // Discard the second event of a jQuery.event.trigger() and // when an event is called after a page has unloaded return typeof jQuery !== “undefined” && (!e || jQuery.event.triggered !== e.type) ? jQuery.event.handle.apply( eventHandle.elem, arguments ) : […]

“在新标签页中打开”的Javascript事件

我有以下问题:我使用Javascript onclick事件来更改链接的href。 它就像一个魅力,但只有当用户点击一个链接时。 如果链接使用“在新选项卡中打开”function – onclick事件将不会触发,href将永远不会更改。 有没有办法处理这样的事件? 也许使用jQuery或其他一些JS Framework? 例: Link 非常感谢!

禁用(并重新启用)href和onclick元素

我只想在元素(a或div)上启用/禁用onclick和href。 我不知道该怎么做。 我可以通过在click事件上添加处理程序来禁用onclick,但href仍然可用。 $(this).unbind().click(function(event){ event.preventDefault(); return; }); 编辑找到了一个元素 if ($(this).attr(“href”)) { $(this).attr(“x-href”, $(this).attr(“href”)); $(this).removeAttr(“href”); }

暂时禁用所有当前活动的jQuery事件处理程序

我在双击时可以编辑表格的TD元素: $(document).on(“dblclick”, “#table>tbody>tr>td.cell”, function(e) { if (e.which != 1 || e.shiftKey || e.altKey || e.ctrlKey) // need left button without keyboard modifiers return; reset_selection(); var editor = document.createElement(“div”); editor.setAttribute(“contenteditable”, “true”); editor.innerHTML = this.innerHTML; this.innerHTML = ”; // this.style.padding = 0; this.appendChild(editor); $(document).on(“*”, stub); editor.onblur = function() { // this.parentNode.setAttribute(“style”, “”); this.parentNode.innerHTML = this.innerHTML; sys.editor = […]

Jquery点击事件不首先点击,但第二次点击,为什么?

我有一个jquery代码,其中 $(“a.reply”).click(function() { //code }); 当我第一次点击.reply类的链接时,没有任何反应。 我第二次点击,点击function内的代码工作。 使用来自mysql数据库的php在页面上插入链接。 所以它没有被动态插入。 为什么会这样? 有解决方案吗 BadASS代码: $(function(){ //TextArea Max Width var textmaxwidth = $(‘#wrapper’).css(‘width’); //Initialize Focus ids To Different Initially var oldcommentid = -1; var newcommentid = -2; //End Of initialization $(“a.reply”).click(function() { newcommentid = $(this).attr(‘id’); if (newcommentid == oldcommentid) { oldcommentid=newcommentid; $(“#comment_body”).focus(); } else { $(‘#comment_form’).fadeOut(0, function(){$(this).remove()}); var […]

使用jQuery绑定AngularJS元素指令上的事件

我在AngularJS中有一个指令: module = angular.module(“demoApp”, [], null); module.directive(‘sample’, function () { return { restrict: “E”, transclude: true, replace: true, template: “”, controller: function ($scope, $element) { this.act = function (something) { //problematic line HERE $element.trigger(“myEvent.sample”, [something]); }; } }; }) .directive(‘item’, function () { return { restrict: “E”, require: “^sample”, transclude: true, replace: true, template: “”, […]

使用jQuery按下输入键时单击链接

我试图这样做,当用户在文本框中并按Enter键时,它与单击链接相同,在这种情况下,它应该将它们带到另一个页面。 这就是我所拥有的,它不起作用。 代码 //jQuery $(document).ready(function() { //if focus is in the input box drivingSchoolInput $(“#drivingSchoolInput”).live(“click”, function() { //if enter key is pressed if(e.keyCode == 13) { //click the button and go to next page $(“#button1”).click(); } }); }); 标记 Search by Driving School Submit