There are some tasks here:
- Get the right input's value
var task = $(f.target).closest('.dropdown-menu').next().val();
$(f.target).closest('.dropdown-menu')
gets you to the dropdown and the input is next()
to it.
localStorage.setItem
accepts 2 arguments: (1) The key name (2) The data (You pass only the key).
-
- In order to set the input's value to the value stored in localStorage, you need to store each input as a different key (not just
input
).
- You need to iterate the inputs and set its value from
localStorage
.
- Since the value you store is string, you don't need to
stringify
/ parse
.
Another point is the inconsistency name
and id
. The first element (the one you clone later) has none. Also the id
and name
are different values because you increase it between (length++
)
https://jsfiddle.net/moshfeu/kw8jfg1m/32/
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…