开发者

Modifying a jQuery Plugin

I'm trying to modify Brian Reindel's Accessible News Slider plugin (sorry, it won't let me link to it and also to my work location), to allow a visitor to fill in multiple copies of a form, sliding back and forth between them. I need for the visitor to be able to add and delete copies of the form from the list. I've modified one of his examples and created a little function to add an element 开发者_运维技巧to the list. However, no matter how many times I call the function, it only adds one element, and the plugin is not aware of it; I can see it in the DOM Inspector, but that's it. What am I missing?


this is Brian. Since you're already using jQuery and the plugin, you would gain a great deal by using the library to append elements to the DOM within your custom function. I wanted to give you some guidance, since this is probably more work than you were inititally expecting. Here are some hopefully helpful tips:

  • The plugin calculates some wrapper element widths based upon the number of list items. If you add/remove list items, then you would need to modify the calculations that were made or else it won't scroll properly. You'll probably experience the same types of issues for the click events on the next/previous buttons.
  • If you have events registered on elements that you add/remove from the DOM, then you will need to re-register those events, since when the elements are gone, so are the events that were "bound" to them. It doesn't look like this is your problem though at this point.
  • If you're adding form elements to the DOM on the fly using the "Add" link, then the user's cursor focus is no longer on the form elements, and the slider is no longer really accessible. As much as I love plugging my own plugin, it was meant mostly to demonstrate usable, custom styled accessible JavaScript, and I'm not sure it is flexible enough to do what you want without some rework.

If you have more specific questions about how to do certain things to get you started on the right track, let me know, and I would be happy to help. Depending on how much you plan to use jQuery on your projects (and I highly recommend that you use it), try out the book Learning jQuery.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜