admin管理员组文章数量:1426644
I want to add separators to php-generated list with jQuery
<select>
<option value="0">all</option>
<option value="1">option 1</option>
<option value="2">option 2</option>
<option value="3">option 3</option>
<option value="4">other</option>
</select>
How to put separators after first eleent and before the last element that result is
<select>
<option value="0">all</option>
<option value="-1" disabled="disabled">------</option>
<option value="1">option 1</option>
<option value="2">option 2</option>
<option value="3">option 3</option>
<option value="-1" disabled="disabled">------</option>
<option value="4">other</option>
</select>
?
Thank you
I want to add separators to php-generated list with jQuery
<select>
<option value="0">all</option>
<option value="1">option 1</option>
<option value="2">option 2</option>
<option value="3">option 3</option>
<option value="4">other</option>
</select>
How to put separators after first eleent and before the last element that result is
<select>
<option value="0">all</option>
<option value="-1" disabled="disabled">------</option>
<option value="1">option 1</option>
<option value="2">option 2</option>
<option value="3">option 3</option>
<option value="-1" disabled="disabled">------</option>
<option value="4">other</option>
</select>
?
Thank you
Share Improve this question asked Apr 28, 2013 at 9:37 user2301515user2301515 5,1176 gold badges36 silver badges50 bronze badges 1-
1
Why not do this in php while you're generating the
select
? – David Thomas Commented Apr 28, 2013 at 9:41
3 Answers
Reset to default 6var $ops = $('select option'), //refine selector if needed
$sep = $('<option>', { text: '------', disabled: true, value: -1 });
$ops.first().after($sep.clone()).end()
.last().before($sep);
Fiddle
Reference:
- Traversing - Filtering
- Manipulation - DOM Insertion, Outside
Don't know if it's exactly what you need, but the <optgroup>
tag does something like that
Shorter code:
$("option[value=0]").after('<option value="-1" disabled="disabled">------</option>');
本文标签: JavascriptHTMLinserting option list separatorsStack Overflow
版权声明:本文标题:javascript - Html, inserting option list separators - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745447280a2658721.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论