javascript - Jquery - Detect click options disabled HTML select -
$(function(){ $("select:option").on('click', this, function(event) { event.preventdefault(); alert("a"); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select name="options" id="options"> <option value="">select</option> <option value="1">options 1</option> <option value="0" disabled="disabled">options 2</option> <option value="0" disabled="disabled">options 3</option> <option value="0" disabled="disabled">options 4</option> </select>
i need check jquery, if user clicked on option of selector disabled, if user clicked display alert().
example: select several options, options in select have value of 0 disabled, if user clicks on of these options disabled, show an alert().
<select name="options" id="options"> <option value="">select</option> <option value="1">options 1</option> <option value="0" disabled="disabled">options 2</option> <option value="0" disabled="disabled">options 3</option> <option value="0" disabled="disabled">options 4</option> </select>
i appreciate help!
$(function(){ var options_sel_idx = 0; $("#options").on("change", this, function(event) { if($(this.options[this.selectedindex]).hasclass("disabled")) { alert("a"); this.selectedindex = options_sel_idx; } else { options_sel_idx = this.selectedindex; } }); });
<style type="text/css"> .disabled {color:#808080;} </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select name="options" id="options"> <option value="">select</option> <option value="1">options 1</option> <option value="0" class="disabled">options 2</option> <option value="0" class="disabled">options 3</option> <option value="0" class="disabled">options 4</option> </select>
Comments
Post a Comment