在模式引导中设置选择选项'selected' [英] set select option 'selected' in a modal bootstrap
本文介绍了在模式引导中设置选择选项'selected'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个选择字段,我必须用jQuery选择其中一个选项。我有这种方法,除了在模式中,它适用于我的任何地方。
当我打开我的目标页面时,它会自动打开一个模式,并选择一个字段,我试图设置他所选择的项目。
我有以下HTML :
< div class ='modal small fade'id =myModal2tabindex = - 1role =dialog aria-labelledby =myModalLabelaria-hidden =true>
< div class =modal-dialog>
< div class =modal-content>
< form method =postaction =UpdateMPrv>
< select id =echellename =echelleclass =form-control>
< option value =mensuelle> Mensuelle< /选项>
< option value =trimestrielle> Trimestrielle< / option>
< option value =semestrielle> Semestrielle< /选项>
< option value =annuelle> Annuelle< /选项>
< option value =aucun> Aucun< /选项>
< / select>
< input type =submit/>
< / form>
< / div>
< / div>
< / div>
script:
<脚本>
var echelle = document.getElementById('echelle');
echelle.value ='trimestrielle';
< / script>
相同的代码,在同一个页面上工作,只有当我把选择字段放在主页面,我的意思是不在模态中,任何人都可以帮助吗?
解决方案 p>
I have a select field and I have to select one of those options with jQuery. I have this method, and it works for me anywhere, except in a modal. When I open my target page, it opens a modal automatically with a select field which I am trying to set his selected item.
I have the following HTML:
<div class='modal small fade' id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form method="post" action="UpdateMPrev" >
<select id="echelle" name="echelle" class="form-control">
<option value="mensuelle"> Mensuelle</option>
<option value="trimestrielle">Trimestrielle</option>
<option value="semestrielle" > Semestrielle</option>
<option value="annuelle" > Annuelle</option>
<option value="aucun"> Aucun</option>
</select>
<input type="submit"/>
</form>
</div>
</div>
</div>
script:
<script>
var echelle= document.getElementById('echelle');
echelle.value = 'trimestrielle';
</script>
the same code, at the same page works, only if I put the select field in the main page, I mean not in the modal, can any one help?
解决方案
you should put your script before showing the modal.
这篇关于在模式引导中设置选择选项'selected'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文