admin管理员组文章数量:1410697
When I select a new value (3) in a drop down menu, I see that HTML still has the old value (10) as "selected".
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10" selected="selected">10</option>
EDIT 1: the problem manifests itself when I clone the form. The cloned copy has its selected option reset. Is there a way to clone the selected value too?
When I select a new value (3) in a drop down menu, I see that HTML still has the old value (10) as "selected".
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10" selected="selected">10</option>
EDIT 1: the problem manifests itself when I clone the form. The cloned copy has its selected option reset. Is there a way to clone the selected value too?
Share Improve this question edited Jan 30, 2014 at 2:49 jazzblue asked Jan 29, 2014 at 23:56 jazzbluejazzblue 2,4375 gold badges41 silver badges63 bronze badges 6- Can you prepare a fiddle? – hemanth Commented Jan 29, 2014 at 23:59
- 1 The property is updated, so this is not an issue, what you're seeing is the attribute in the HTML – adeneo Commented Jan 30, 2014 at 0:00
- This question appears to be off-topic because it is about not being able to see property changes when viewing the HTML. – adeneo Commented Jan 30, 2014 at 0:02
- 1 The selected attribute sets the default selected option, it does not necessarily indicate the currently selected option. The selected property always indicates whether an option is currently selected or not. – RobG Commented Jan 30, 2014 at 0:03
- How are you "detaching" the form? Likey you need to read the current values before detaching, then reassign them afterward. Same again when you reattach the form. Or change how the form is detached/reattached so the values aren't changed. – RobG Commented Jan 30, 2014 at 0:06
1 Answer
Reset to default 5The reason you are seeing this is that changing the selected index will not alter the attribute on the html element itself. However, the value actually is changed.
See this demo
for an example of what the selected index shows when changed
本文标签: javascriptquotDropdownquot selected value not updated in HTMLStack Overflow
版权声明:本文标题:javascript - "Drop-down" selected value not updated in HTML - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744248145a2597120.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论