问题
I am generating a dynamic html table. One of the columns in the table has a clickable image (a href
). For testing, I have also created a static table, with similar structure as the dynamic table, in the same div.
I have defined a selectors/a/click.js
event handler, which works fine for the links in the static table, but not in the dynamic table.
It seems that, since the table is dynamically generated, evently is not attaching any event handlers to it.
Could somebody suggest a workaround for this?
回答1:
I found a workaround: use live
instead of bind
in the evently library:
cd vendor/couchapp/_attachments
cat jquery.evently.js | sed -e 's!\.bind(!.live(!'
I'll try to push this upstream into evently.
回答2:
Alternatively, you may lay your events in a following way:
table/<event>/selectors/a/click.js
(where is event responsible for filling your dynamic table, for example _changes
). This ensures that the events are being bound after table is generated.
来源:https://stackoverflow.com/questions/7982493/event-listeners-for-dynamic-content-in-evently