最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - "Drop-down" selected value not updated in HTML - Stack Overflow

programmeradmin6浏览0评论

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
 |  Show 1 more ment

1 Answer 1

Reset to default 5

The 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

发布评论

评论列表(0)

  1. 暂无评论