jquery-events

How to detect pressing Enter on keyboard using jQuery?

徘徊边缘 提交于 2020-01-08 09:30:50
问题 I would like to detect whether the user has pressed Enter using jQuery. How is this possible? Does it require a plugin? EDIT: It looks like I need to use the keypress() method. I wanted to know if anyone knows if there are browser issues with that command - like are there any browser compatibility issues I should know about? 回答1: The whole point of jQuery is that you don't have to worry about browser differences. I am pretty sure you can safely go with enter being 13 in all browsers. So with

Remove a script with jQuery

匆匆过客 提交于 2020-01-05 12:42:09
问题 I have a problem with my jQuery. So, I want to remove a script who is inside a <div> . My html is : <div id="right-bloc"> <div class="right-bloc-pub-1"> <script type="text/javascript" src="http://firstScript.com"></script> </div> <div class="right-bloc-pub-2"> <script type="text/javascript" src="http://secondScript.com"></script> </div> </div> My jQuery : var stringOfHtml = '<script type="text/javascript" src="http://firstScript.com"></script>'; var html = $(stringOfHtml); html.find('script')

Remove a script with jQuery

房东的猫 提交于 2020-01-05 12:42:07
问题 I have a problem with my jQuery. So, I want to remove a script who is inside a <div> . My html is : <div id="right-bloc"> <div class="right-bloc-pub-1"> <script type="text/javascript" src="http://firstScript.com"></script> </div> <div class="right-bloc-pub-2"> <script type="text/javascript" src="http://secondScript.com"></script> </div> </div> My jQuery : var stringOfHtml = '<script type="text/javascript" src="http://firstScript.com"></script>'; var html = $(stringOfHtml); html.find('script')

.on not working on dynamic html

女生的网名这么多〃 提交于 2020-01-05 03:49:04
问题 I am creating drag and drop thing. When drop happens I create new runtime html and want to bind it event, so I have used following .on .on ( "event", "selector", function() { but its not working. Here is Snippet : $( "#wrap .dragImages" ).on( "click", "button.edit-new-modal", function() { var photoId = $(this).attr('data-username'); alert(photoId); }); .on works before drag and drop. But afterwords nothing happens on clicking "button.edit-new-modal"!! What's wrong? Any solution? 回答1: try : $

Redirect on change of large select menu in jQuery Mobile

…衆ロ難τιáo~ 提交于 2020-01-04 06:53:07
问题 I'm having an issue with trying to redirect to another page when a user selects an option from a <select> menu in jQuery Mobile. Below is a very small example similar to what I'm trying to do that demonstrates the issue I'm having. The problem is that when the list of options is too big to fit on the screen, the redirect does not work. It works fine when the options fit on the screen. (You can reproduce this in a desktop browser by making your window really small.) <!DOCTYPE html> <html>

How to detect which <td> is clicked

孤街醉人 提交于 2020-01-03 13:32:25
问题 I have the following case: I have a with some and . I need to detect which was clicked (eventually get the Id). I have build the following JS Fiddle as a reference. jQuery(document).ready(function() { $(".table").find("tr").click( function(){ alert("<tr> clicked"); var td2 = $(this).find(".td2:first").text(); alert(td2); }); }); I have a .click() event and I am doing some actions when is clicked but I need to detect if a specific <td> is clicked in order to exclude that TD. Basically when any

Stop event bubbling - increases performance?

对着背影说爱祢 提交于 2020-01-03 12:35:27
问题 If I'm not returning false from an event callback, or using e.stopPropagation feature of jQuery, the event bubbles up the DOM. In most scenarios I don't care if the event bubbles or not. Like with this DOM structure example: ​<div id="theDiv"> <form id="theForm" > <input type="submit" value="submit"/> </form> </div>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ Normally, I don't have multiple nested submit callback like this: $('#theDiv').submit

Disabling Tabs in Bootstrap

前提是你 提交于 2020-01-03 08:26:13
问题 I am trying to disable the tabs in bootstrap. I have been researching and I have not yet found a solution. I have tried this: Can you disable tabs in Bootstrap? It has lead me to the bootstrap issues... I also tried $('.disabled').removeData('toggle'); I looked here.. https://github.com/twitter/bootstrap/issues/2764 Solution Attempted: - Returning false jQuery disable a link Solution Attempted: - event.defaultPrevented(); And yet I have not come up with an answer. So far my problem is that

Does jQuery off method remove event listeners added with addEventListener?

谁说胖子不能爱 提交于 2020-01-02 07:22:09
问题 I am working on an old code and I have seen in the code that there are many events added with javascript addEventListener and some added with jQuery.on() on the same element but in the detach method it is used only jQuery.off() to remove them. So I was wondering if this code will work as the guys that wrote it expected (to remove all events from the dom element) or the events added with javascript won't be removed. 回答1: It does not. If you investigate the native removeEventListener api you

On CTRL+MOUSEWHEEL event

≯℡__Kan透↙ 提交于 2020-01-02 07:05:03
问题 I was asked to implement ctrl+mousewheel event for our page site in order to change image offset on user zoom in or zoom out. I found this old answer Override browsers CTRL+(WHEEL)SCROLL with javascript and I`ve tried to do the same. I downloaded the jQuery Mouse Wheel Plugin for the implementation and here is my code: var isCtrl = false; $(document).on('keydown keyup', function(e) { if (e.which === 17) { isCtrl = e.type === 'keydown' ? true : false; } }).on('mousewheel', function(e, delta) {