开发者

jquery add remove inputs

My jQuery right now works perfectly when I use it to perform creation, and deletion, of textboxes. But the code does not work properly when I decide to allow users to edit them after they sub开发者_开发百科mit and the same code upon modification does not work anymore.

My rules are such that there needs to be a minimum of 2 iterations boxes and 1 task in each iteration, anything less than that would cause the jQuery to disable my remove iteration and minus task button respectively.

Now my codes cannot seem to allow a user to reduce a task even though there is more than 1 task in the iteration and the remove iteration button is forever disabled, despite starting off with, say, 5 iterations.

I cannot remove the 'disable' at the beginning because a user may end up with zero task if he has only filled in one task, so I can only remove the 'disable' once the if-loop proves that there is more than the minimum required.

HERE is my jQuery code, can somebody please help and give some advice? :)) Thanks in advance!

PS: $('.plus') refers to my add task class button, $('.moins') refers to my minus task class button, $('#removeIteration') and $('#addIteration') both represent remove iteration and add iteration respectively.


Please give us some context on your problem (what is it exactly your code is supposed to do, and how is it doing it right now (a rough description of your approach is enough), and paste only the relevant code in your question. Right now it is not clear at all what you mean with iteration, as you do not explain what your iterations are supposed to be doing.

--edit 1

I see you have split up the question in paragraphs, very good. Please keep making it better by providing the context.

--edit 2

I see you use parent().parent().parent(). This is rather inflexible code. You should use .closest('query describing the parent you are looking for').

Instead of 'return false;' you should use 'event.preventDefault();' and edit the lines like

$(".moins").live("click", function() {

to

$(".moins").live("click", function(event) {
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜