|
You last visited: Today at 11:14
Advertisement
e.target Attributes Problem
Discussion on e.target Attributes Problem within the Web Development forum part of the Coders Den category.
02/08/2020, 21:16
|
#1
|
elite*gold: 0
Join Date: Mar 2011
Posts: 422
Received Thanks: 17
|
e.target Attributes Problem
Guten Tag,
ich habe viele Beiträge und unter jedem Beitrag kann man kommentieren oder ein Bild posten. Wenn ich jetzt ein Bild posten möchte klicke ich auf das Foto-Symbol (In Html:
HTML Code:
<input type="file" name="uploadImageComment" class="inputfile2comment" id="file1comment" data-attr-id="<?= $row['beitrag_id']; ?>">
<label for="file1comment" style="margin-top:-2.5px;color:rgba(73, 223, 210, 1);background-color:#fff;max-width:unset;width:auto;vertical-align:middle;padding:4px;border-radius:8px;">
<i class="fas fa-camera"></i>
</label>
Jedes Foto-Symbol hat ein Attribute namens: Data-Attr-Id. Dort wird die Beitrag ID gespeichert. Ich möchte jetzt beim betätigen des Foto-Symbols die Beitrag ID des Foto-Symbols bekommen.
Wenn ich jetzt auf den ersten Beitrag draufklicke, zeigt er mir es an wunderbar. Aber wenn ich jetzt nach unten scrolle zeigt er mir die Beitrag ID Des ersten Beitrages an. Egal welches Symbole ich klicke , es wird immer die gleiche Beitrag ID angezeigt obwohl jedes Data-Attribute eine andere Beitrag ID hat.
JS:
PHP Code:
$('.inputfile2comment').on('change', function(e) { // var upload = e.target.value; var id = e.target.getAttribute('data-attr-id'); alert(id);
});
Weiß jemand woran es liegt?
|
|
|
02/09/2020, 01:28
|
#2
|
elite*gold: 0
Join Date: Apr 2011
Posts: 11,115
Received Thanks: 2,436
|
Bitte stell mal ein laufendes Beispiel zur verfügung, das erleichtertet das helfen deutlich ! (Dafür kannst du z.b. jsfiddle nutzen).
Wenn du eh schon Jquery nutzt, kannst du übrings
Code:
var id = $(e.target).data("attr-id');
statt
Code:
var id = e.target.getAttribute('data-attr-id');
nutzen
|
|
|
02/09/2020, 02:26
|
#3
|
elite*gold: 0
Join Date: Apr 2011
Posts: 363
Received Thanks: 167
|
I think the problem is because he's loading dynamic content when scrolling down, but new content won't work with already registered listeners, so in order to make them work u should add a listener to your new elements, the fast way to do it is remove current class listener and register it again after adding the new content
|
|
|
02/09/2020, 12:02
|
#4
|
elite*gold: 0
Join Date: Apr 2011
Posts: 11,115
Received Thanks: 2,436
|
Quote:
Originally Posted by elmarcia
I think the problem is because he's loading dynamic content when scrolling down, but new content won't work with already registered listeners, so in order to make them work u should add a listener to your new elements, the fast way to do it is remove current class listener and register it again after adding the new content
|
I dont think this is the problem. If that would the problem he would get no id, instead of the same id.
Also he wouldnt need to remove the listener and add it again, he could use
Code:
$('body').on('eventName', 'targetSelector', function)
instead of
Code:
$('targetSelector').on('eventName', function)
|
|
|
02/10/2020, 09:02
|
#5
|
elite*gold: 0
Join Date: Jun 2013
Posts: 405
Received Thanks: 84
|
Liegt es nicht daran, dass immer das erste gefundene Element den Eventlistener bekommt?
Also müsstest du nicht so etwas in der Art machen:
Code:
var inputs = document.querySelectorAll(".inputfile2comment");
inputs.forEach(input => {
input.addEventListener("change", e =>
console.log(e.target.getAttribute("data-attr-id");
});
|
|
|
02/10/2020, 20:05
|
#6
|
elite*gold: 0
Join Date: Apr 2011
Posts: 11,115
Received Thanks: 2,436
|
Quote:
Originally Posted by lnqlorlouz
Liegt es nicht daran, dass immer das erste gefundene Element den Eventlistener bekommt?
Also müsstest du nicht so etwas in der Art machen:
Code:
var inputs = document.querySelectorAll(".inputfile2comment");
inputs.forEach(input => {
input.addEventListener("change", e =>
console.log(e.target.getAttribute("data-attr-id");
});
|
Nein, wenn wenn es mehrere Elemente für den Selector gibt, dann bekommen alle das Event.
(Sofern man Jquery nutzt => Was er tut)
|
|
|
02/12/2020, 17:25
|
#7
|
elite*gold: 0
Join Date: Jun 2013
Posts: 405
Received Thanks: 84
|
Quote:
Originally Posted by False
Nein, wenn wenn es mehrere Elemente für den Selector gibt, dann bekommen alle das Event.
(Sofern man Jquery nutzt => Was er tut)
|
Stimmt, da war was. Ich arbeite zum Glück nicht mit jQuery. Die meisten Sachen gehen heutzutage auch so ziemlich einfach, dank Babel und alle neuen Dinge ab ES5.
Ich denke der Threadersteller hat schon eine Lösung(?), falls nicht, bräuchten wir mehr Code oder du setzt mal ein debugger Statement.
|
|
|
 |
Similar Threads
|
Target self / Target enemy ? >.>
03/21/2011 - General Gaming Discussion - 2 Replies
Well, i just looked through all the existing rose-hack-threads (not that any of them would work...), when i saw those "Levelbots" with a "Target self" and a "Target Enemy" Skill :o
Well, my question is: Where can i find this Skill? O_o I´m playing AruaRose, but i neither got it from beginning nor being able to buy it anywhere :o
Well, it would be nice if u could tell me... :>
Edit: Oh, and if one of the Maker of those "Rose online Privatserver"-Threads should read this, would you...
|
WoW Hide My Target - Hide your target!
10/24/2010 - WoW Exploits, Hacks, Tools & Macros - 46 Replies
Voerst: Hier geht es um einen kleinen Hack, um euer Target zu verstecken. Andere werden euer aktuelles Target nicht mehr sehen. Dieser kleine Hack ist aus Langeweile entstanden, wenn ihr ihn also unnütz findet, steht es euch frei diesen Thread ohne jeglichen noch sinnloseren Kommentar zu verlassen, danke!
Wie funktioniert der Hack?
Code der verändert wrid in WoW:
00518E07 - 5 Bytes (0x90, 0x90, 0x90, 0x90, 0x90)
00524311 - 5 Bytes (0x90, 0x90, 0x90, 0x90, 0x90)
00528306 - 5 Bytes...
|
[Help] Invalid Target/Cannot find Target(ZSZC)
05/29/2010 - SRO Private Server - 4 Replies
Some write they have Problems with ZSZC SRO-DB,
by mobs for example "Ishade/Penon/Ujigi(lvl50-56)",
in the Textbox right side down a message:
"Invalid Target" or " Cannot Find Target",
All have this Problem, a good message, i have the solution!
You need Use SRO-DB Bot V0.8 and NOT V0.9a!
+++Use this and you will have Fun by Botting+++
|
All times are GMT +2. The time now is 11:14.
|
|