option

Dependent <select> menus in HTML and JavaScript

拟墨画扇 提交于 2019-11-27 09:06:20
问题 I have two <select> fields in my page. The first is shown below with some illustrative brand names: <select name="1"> <option value="Apple">Apple</option> <option value="Samsung">Samsung</option> <option value="other">Other</option> </select> If the user selects "Apple" in this first field, I would like the second to contain Apple's products for the user to choose from, such as <select name="Apple"> <option value="iphone">iPhone 7</option> <option value="ipad">iPad Super Pro</option> <option

How to hide optgroup/option elements?

一曲冷凌霜 提交于 2019-11-27 09:00:58
Is there a way to hide option or optgroup HTML elements? I've tried calling hide() in jQuery, and also using regular Javascript to set style.display='none' . It works in Firefox but not in any other browsers. Actually removing them from the DOM does work, so perhaps there's a way to save each DOM element when it's removed, and reinsert them in the same place? My HTML is like this: <select name="propsearch[area]" id="propsearch_area"> <option value="0">- Any -</option> <optgroup label="Bristol"> <option value="Hotwells">Hotwells</option> <option value="Montpelier">Montpelier</option> </optgroup

JQuery :contains function limit to exact match

戏子无情 提交于 2019-11-27 06:54:18
问题 Using the JQuery :contains function to decide which option on a select is selected from a SESSION variable. The contains function is matching the wrong option as their is an option 'PADI Open Water' and another 'PADI Open Water Scuba Instructor' How do we limit it to match the exact content and no more? $('option:contains("<?php echo $_SESSION['divelevel'];?>")').attr('selected', 'selected'); 回答1: Try using .filter(), to find the option you want. $('option').filter(function(){ return $(this)

set option “selected” attribute from dynamic created option

ぐ巨炮叔叔 提交于 2019-11-27 06:24:36
I have a dynamically created select option using a javascript function. the select object is <select name="country" id="country"> </select> when the js function is executed, the "country" object is <select name="country" id="country"> <option value="AF">Afghanistan</option> <option value="AL">Albania</option> ... <option value="ID">Indonesia</option> ... <option value="ZW">Zimbabwe</option> </select> and displaying "Indonesia" as default selected option. note : there is no selected="selected" attribute in that option. then I need to set selected="selected" attribute to "Indonesia", and I use

How to get attribute from selected option of select in jQuery?

假如想象 提交于 2019-11-27 05:50:29
问题 I have the next selectbox in HTML: <select id="listbox-taskStatus" class="selectpicker"> <option status="0">In progress</option> <option status="1">Not started</option> <option status="2">Done</option> <option status="3">Failed</option> </select> I want to read the attribute value from selected option. If just to take the value, it's simple: var value = $('#listbox-taskStatus').val(); But what should I do, if I want to get the attribute value from selected option? I know, that .attr() must

jQuery获取input值、select值、select文本

老子叫甜甜 提交于 2019-11-27 05:45:27
使用jQuery时如果不能区分jQuery对象和Dom对象,会常常它们对应的方法,笔者在工作过程中也是常常查阅资料加深记忆。 jQuery获取input值: 对应的html代码 <input id= "input_example" type = "text" placeholder= "此input example 用来获取input的value值" /> 对应的jQuery代码 var input_value = $( '#input_example' )[ 0 ]. value ; jQuery获取select值 对应的html代码 < select id +" select_example > < option value = "option_value_1" > option text 1 </ option > < option value = "option_value_2" > option text 2 </ option > < option value = "option_value_3" > option text 3 </ option > </ select > 对应的jQuery代码 var select_value = $( "select_example" ).val(); jQuery获取select文本 对应的html代码 < select id

how to make sure select option text align in the center in IE?

和自甴很熟 提交于 2019-11-27 05:34:33
The following CSS works in FF, but not in IE(at least 8.0), how can I make sure that the text align in the center for IE8.0? Thanks!!! select, option { text-align: center; } Unfortunately, you can't change the alignment of SELECT items in IE, although it surprises me that even IE 8 keeps this bad habit. Given that this is not possible in IE, I think you would have to resort to: Implementing your own SELECT widgets. There are many JS libraries that do this, mostly because SELECT inputs are hard to style. Insert the appropriate whitespace in front of the smaller options. Edit: looks like

JQuery Hide Option doesn't work in IE and Safari

[亡魂溺海] 提交于 2019-11-27 04:49:01
I'm trying to hide a few options in a dropdown box using .hide(). This works perfectly fine in firefox and chrome, but it doesn't work in IE and Safari. My original code is more complex but I've narrowed it down to this. I've tried several combinations and nothing has worked. .hide() works, but not for things within option tags for some reason. Can someone please help me? This is driving me nuts. Thank you so much for taking the time help! Here's my jscript: <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("

ie6 select不兼容处理(转)

跟風遠走 提交于 2019-11-27 04:10:48
jQuery针峰相对IE6 以下是个人在使用jQuery在开发时,与ie6有关的bug 1:关于select下拉框的动态赋值并选中其中某一项 在ie6中,如果你动态给select赋值并选中时,如下代码: $('#selectId').empty().html('<option value="001">collonn</option><option value="002">joanna</option>').val('002') alert('following'); 这样写,最终的结果是: (1)会选中valu='002'的选项,但ie6会报错(浏览器左下角会出现一个黄色报警) (2)alert('following')这一行是不会执行的,并且,这一行以下的所有js都不会执行 解决方法: 应该这样写: $('#selectId').empty().html('<option value="001">collonn</option><option value="002">joanna</option>'); setTimeout(function(){ $('#selectId').val('002'); },10); 问题解决,但不知道根本原因,可能是ie6还没有来得及给select做必要的处理吧 2:关于table的显示与隐藏样式 如果隐藏就用:$('#table').css(

如何用jQuery获得select的值

核能气质少年 提交于 2019-11-27 03:03:34
1.获取第一个option的值 $('#test option:first').val(); 2.最后一个option的值 $('#test option:last').val(); 3.获取第二个option的值 $('#test option:eq(1)').val(); 4.获取选中的值 $('#test').val(); $('#test option:selected').val(); 5.设置值为2的option为选中状态 $('#test').attr('value','2'); 6.设置最后一个option为选中 $('#test option:last').attr('selected','selected'); $("#test").attr('value' , $('#test option:last').val()); $("#test").attr('value' , $('#test option').eq($('#test option').length - 1).val()); 7.获取select的长度 $('#test option').length; 8.添加一个option $("#test").append("<option value='n+1'>第N+1项</option>"); $("<option value='n+1'>第N+1项