Select OnChange

懵懂的女人 提交于 2019-12-13 09:33:20

问题


This is a simple question.

How do I change the "badge's price from $10 to $20" with select onChange?

<span class="badge badge-primary">$10</span>

<select>
 <option>$10 Item</option>
 <option>$20 Item</option>
</select>

Please provide the HTML and jQuery.

P.S. I don't want to use an image for the badge's price. Thanks.


回答1:


HTML:

<span id="mybadge" class="badge badge-primary">$10</span>

<select id="myselect">
 <option value="$10">$10 Item</option>
 <option value="$20">$20 Item</option>
</select>

Javascript:

$('#myselect').change(function(){
    $('#mybadge').text($(this).val());
});

Working jsFiddle ->> http://jsfiddle.net/sUBWd/5/



来源:https://stackoverflow.com/questions/15137744/select-onchange

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!