value attribute in <input> tag #939

Closed
ColorFuzzy opened this Issue Mar 13, 2014 · 2 comments

Projects

None yet

2 participants

@ColorFuzzy

Put <input value=5 id="input"> in body and input a 10 in input field.
$("#input").attr("value") will return 10;
$("#input").attr("value", 20) will replace value=5 to value=20, but the input field will not change.

  1. I can't get the value attribute value.
  2. I can't set the input field value.

pure javascript:
document.getElementById("input").value will get(can set) input field value;
document.getElementById("input").g[s]etAttribute("value", 20) will get/set value attribute.

@madrobby
Owner

Use val to get and set input field values, see http://zeptojs.com/#val

@ColorFuzzy

I can use val() to get/set input field values and I can also use $("#input").attr("value", 20) to set the value attribute value, but how can I get the value attribute value? $("#input").attr("value") and $("#input").val() both return the same value in input field.
The main problem is $("#input").attr("value", 20) and $("#input").attr("value") take effect on different place, this would confuse people.

@mislav mislav closed this in #960 Jun 16, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment