So I was struggling with this for some time. I have a list of inputs, and focus and update the event based on the clicked / focused input. I use JQuery for this.
& lt; Body & gt; & Lt; Input id = "d1" type = "article" value = "A" & gt; & Lt; Input id = "d2" type = "text" value = "something" & gt; & Lt; Input id = "d3" type = "text" value = "word" & gt; & Lt; / Body & gt;
What do I need
- When I click on an input, the selection should be cleared (if CTRL not is pressed), and the clicked input should be added to the selection.
- When I input into input, as it is above, but always clear selection
- Forward through input with tab, clear selection, and Currently focused input should be added to selection.
Whatever I tried
& lt; Script type = "text / javascript" & gt; Var stuff = {}; $ (Document) .ready (function () {for (var i = 1; i & lt; = 3; i ++) {var selector = "#d" + i; $ (selector) .on ({"focusin "Function stuff [selector] = true;}," click ": function (event) {if (! Event.ctrlKey) {stuff = {};} stuff [selector] = true;}});}}) ; & Lt; / Script & gt;
However, the cause of click
a focuses
, so the selection is always clear, so I created the ctrlKey
Tried to get from focusin
event, but only mouse events have a ctrlKey
attribute
My question (s)
Is it possible for the focus cell
to know that this is a
click on the event? Or am I using the wrong listeners?
I searched Google for a while, but when I add focus
, most sites are about focusing an element with jQuery, or An element is centered, or checked, so unfortunately, that I did not find it, I found it, though, but I can not answer myself:
Because the focus event always fire, "focus only" "After the focus, do not appear outside the box separately" Click on "Events"
But you can use this with simplifying your various steps Step 1: Since the focus event always Already being removed, selection is done and updating with current value is done here. Step 2: Whenever a click event will be met with ctrl condition, then later, we can backup the selection data Take, before That we remove them step 3: the click event either restores the backup selection to the Ctrl position, or removes the backup (because it has already been updated in the focus event)
In the code it means:
var stuff = {}; // The empty global luggage object var oldStuff = {}; // Blank global backup object $ ('Input'). ({"Focusin": Function (event) {oldstuff = stuff; // Backup your baggage stuff = {}; // Remove the contents of your content [$ (this) .attr ('id')] = $ ( This) .val (); // Get current value console.log ("Focused stuff"); console.log (stuff); // Show it in console}, "click": function {event} { If (event.ctrlKey) {// if ctrl key was used $ .extend (stuff, old staff); // merge old stuff in stuff again} and if (! Event.ctrlKey) {oldstuff = {} ; // older Stuff} console.log delete ("Cl That was stuff "); console.log (stuff); // show stuff}});
No comments:
Post a Comment