jquery-events

jQuery autocomplete @mention

女生的网名这么多〃 提交于 2019-12-19 11:49:28
问题 I have this autocomplete plugin from Andrew Whitaker - DEMO Lets say I have a string in a textarea "@peterwateber welcome" I want it to output in a hidden tag as "@[peterwateber] welcome" how should I do it? I'm not that good at Javascript... I've tried looking at this code here from Hawkee 回答1: I wrote the original code mentioned here and have fixed the menu problem Peter was having: http://www.hawkee.com/snippet/9391/ 回答2: Hiya Working demo here: http://jsfiddle.net/67dxH/ Already had good

Detect a window width change but not a height change

落爺英雄遲暮 提交于 2019-12-18 10:48:26
问题 I'm using the .resize() function to detect window re-size events, but this detects both height and width changes. Is there any way to detect just a width change and not a height change? 回答1: var width = $(window).width(); $(window).on('resize', function() { if ($(this).width() != width) { width = $(this).width(); console.log(width); } }); 回答2: you can detect both events and just execute code when it's a width change: var lastWidth = $(window).width(); $(window).resize(function(){ if($(window)

jQuery $(document).off() not working in Chrome extension

坚强是说给别人听的谎言 提交于 2019-12-18 09:31:53
问题 I've created a Chrome Extension based on https://thoughtbot.com/blog/how-to-make-a-chrome-extension (look at the end for the completed files) I've made two changes: I used jQuery 3.1.1 minimized instead of the older one given in the page above, and I changed content.js: chrome.runtime.onMessage.addListener( function(request, sender, sendResponse) { if( request.message === "clicked_browser_action" ) { $(document).off("touchmove mousewheel mousemove scroll"); } } ); The $(document).off()

.keypress on a DIV tag?

落爺英雄遲暮 提交于 2019-12-18 04:08:23
问题 Is there a way to get work .keypress on a div element like this?: <html> <body> <script type="text/javascript"> <!-- $('#idtext').keypress(function(event) { var keyCode = event.keyCode; $('#idtext').text(function(i, text) { return text + String.fromCharCode(keyCode); }); }); // --> </script> <div id="idtext"></div> </body> </html> 回答1: Yes: you need to add a tabindex attribute to the <div> to allow it to receive the focus. <div id="idtext" tabindex="1"></div> Also, the property you want for

.keypress on a DIV tag?

我的梦境 提交于 2019-12-18 04:08:06
问题 Is there a way to get work .keypress on a div element like this?: <html> <body> <script type="text/javascript"> <!-- $('#idtext').keypress(function(event) { var keyCode = event.keyCode; $('#idtext').text(function(i, text) { return text + String.fromCharCode(keyCode); }); }); // --> </script> <div id="idtext"></div> </body> </html> 回答1: Yes: you need to add a tabindex attribute to the <div> to allow it to receive the focus. <div id="idtext" tabindex="1"></div> Also, the property you want for

Get text from field on keyup, but with delay for further typing

大城市里の小女人 提交于 2019-12-18 03:16:23
问题 I have a form which is submitted remotely when the various elements change. On a search field in particular I'm using a keyup to detect when the text in the field changes. The problem with this is that when someone types "chicken" then the form is submitted seven times, with only the last one counting. What would be better is something like this keyup detected - start waiting (for one second) another keyup detected - restart waiting time waiting finishes - get value and submit form before I

Stop Enter/Return key submitting a form [duplicate]

有些话、适合烂在心里 提交于 2019-12-17 17:06:28
问题 This question already has answers here : Prevent users from submitting a form by hitting Enter (31 answers) Closed 3 years ago . I have a table within a form. The table contains some form fields, but there are form fields outside of the table (but still within the form) too. I know that Enter and Return are traditionally used to submit a form via the keyboard, but I want to stop this behaviour for fields within the table. For example, if I focus a field within the table and hit Enter/Return,

Drop event not firing in chrome

蓝咒 提交于 2019-12-17 10:38:33
问题 It seems the drop event is not triggering when I would expect. I assume that the drop event fires when an element that is being dragged is releases above the target element, but this doesn't seem to the the case. What am I misunderstanding? http://jsfiddle.net/LntTL/ $('.drop').on('drop dragdrop',function(){ alert('dropped'); }); $('.drop').on('dragenter',function(){ $(this).html('drop now').css('background','blue'); }) $('.drop').on('dragleave',function(){ $(this).html('drop here').css(

Get clicked element using jQuery on event?

时光总嘲笑我的痴心妄想 提交于 2019-12-17 06:31:28
问题 I'm using the following code to detect when a dynamically generated button is clicked. $(document).on("click",".appDetails", function () { alert("test"); }); Normally, if you just did $('.appDetails').click() you could use $(this) to get the element that was clicked on. How would I accomplish this with the above code? For instance: $(document).on("click",".appDetails", function () { var clickedBtnID = ?????? alert('you clicked on button #' + clickedBtnID); }); 回答1: As simple as it can be Use

Get clicked element using jQuery on event?

蹲街弑〆低调 提交于 2019-12-17 06:31:09
问题 I'm using the following code to detect when a dynamically generated button is clicked. $(document).on("click",".appDetails", function () { alert("test"); }); Normally, if you just did $('.appDetails').click() you could use $(this) to get the element that was clicked on. How would I accomplish this with the above code? For instance: $(document).on("click",".appDetails", function () { var clickedBtnID = ?????? alert('you clicked on button #' + clickedBtnID); }); 回答1: As simple as it can be Use