如果选中,如何将选中的选项设置为 true
How to set the option selected to true if selected
.filter
select(name="filter")
each list in lists
option(value='?list=' + list, selected=filter == list)= list
HTML 例子
<select name="filter">
<option value='?list=A'> A </option>
<option value='?list=B' selected> B </option>
</select>
selected = filter ==list
什么都不做。不确定哪里出了问题。如果它是 'A' 或 'B'
,则需要能够将选择的选项设置为 true
感谢帮助。
selected
属性只需要存在。它没有价值,设置它是多余的并且可能是错误的。
selected
If present, this Boolean attribute indicates that the option is initially selected. If the <option>
element is the descendant of a <select>
element whose multiple attribute is not set, only one single <option>
of this <select>
element may have the selected attribute.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option
你需要做这样的事情
.filter
- var lists = ['A','B','C'];
select(name="filter")
each list in lists
if(list=='B') // < based on condition
option(selected)= list // include "selected"
else
option()= list // or not
.filter
select(name="filter")
each list in lists
option(value='?list=' + list, selected=filter == list)= list
HTML 例子
<select name="filter">
<option value='?list=A'> A </option>
<option value='?list=B' selected> B </option>
</select>
selected = filter ==list
什么都不做。不确定哪里出了问题。如果它是 'A' 或 'B'
感谢帮助。
selected
属性只需要存在。它没有价值,设置它是多余的并且可能是错误的。
selectedIf present, this Boolean attribute indicates that the option is initially selected. If the
<option>
element is the descendant of a<select>
element whose multiple attribute is not set, only one single<option>
of this<select>
element may have the selected attribute.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option
你需要做这样的事情
.filter
- var lists = ['A','B','C'];
select(name="filter")
each list in lists
if(list=='B') // < based on condition
option(selected)= list // include "selected"
else
option()= list // or not