问题描述
我有一个html表单,并且在获取选定的值时遇到了一些麻烦,这里是html
<形式>
< div class =row>
< div class =form-group col-xs-12 col-md-8>
< label>联络资讯< / label>
< input tabIndex =100class =form-control squareplaceholder =您的电子邮件地址autocomplete =offdata-error-style =inlinename =emailtype =text >
< / div>
< div class =form-group col-xs-12 col-md-4>
< label>性别< / label>
< div class =drop-down-holder>
< div class =simple-dropdown dropdown btn-dropdown dropdown-module dropdown-toggle
data-toggle =dropdown
type =button>
< button tabindex =101class =dropdown-module dropdown-toggletype =buttondata-toggle =dropdowndata-target =#>
< div class =简单持有人>
< div class =dropdown-label>选择性别< / div>
< div class =icon-holder>< i class =icon-caret-down>< / i>< / div>
< / div>
< / button>
< ul class =dropdown-menurole =menu>
< li>< a class =female>女性< / a>< / li>
< li>< a class =male>男性< / a>< / li>
< / ul>
< / div>
< / div>
< / div>
< / div>
< / form>
我已经在控制台中尝试了几件事情,并一直获取空字符串
这就是我已经尝试过了
$(。dropdown-menu)。text();
这个返回字符串中的女性和男性的文本
$(。dropdown-menu)。val();
空字符串
$(。dropdown-menu:selected)。text() ;
也为空字符串
$(。dropdown-menu选项:选择了)文本();
空
$('。dropdown-menu option:selected')。val();
undefined
我可以得到用户选择男性或女性的天气?我需要一个条件语句的值,它会根据他们的性别将它们重定向到某个页面。
大家都知道了答案 $(。dropdown-module)。val();
这是按钮的类,因为引导程序使用div和uls作为我需要的下拉列表,下拉式模块
I have an html form and having a little trouble getting the selected value on it, here is the html
<form>
<div class="row">
<div class="form-group col-xs-12 col-md-8">
<label>Contact Info</label>
<input tabIndex="100" class="form-control square" placeholder="Your email address" autocomplete="off" data-error-style="inline" name="email" type="text">
</div>
<div class="form-group col-xs-12 col-md-4">
<label>Gender</label>
<div class="drop-down-holder ">
<div class="simple-dropdown dropdown btn-dropdown dropdown-module dropdown-toggle"
data-toggle="dropdown"
type="button">
<button tabindex="101" class="dropdown-module dropdown-toggle" type="button" data-toggle="dropdown" data-target="#">
<div class="simple-holder">
<div class="dropdown-label">Select Gender</div>
<div class="icon-holder"><i class="icon-caret-down"></i></div>
</div>
</button>
<ul class="dropdown-menu" role="menu">
<li><a class="female">Female</a></li>
<li><a class="male">Male</a></li>
</ul>
</div>
</div>
</div>
</div>
</form>
I've tried a few things in console and keep getting empty stringsThis is what I've tried
$(".dropdown-menu").text();
This one returns just the text female and male in a string
$(".dropdown-menu").val();
empty string $(".dropdown-menu :selected").text();
also empty string
$(".dropdown-menu option:selected").text();
empty
$('.dropdown-menu option:selected').val();
undefined
So any clue on how I can get weather the user selected male or female? I need that value for a conditional statement that will redirect them to a certain page depending on their gender.
Hey guys figured out the answer
$(".dropdown-module").val();
this is the class of the button, since bootstrap uses divs and uls for dropdown I needed to target the dropdown-module
这篇关于从jquery的html下拉菜单中获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!