ipad禁用没有jquery的选项

我可以使用一种方法,插件或代码片段

.... 

在ipad上的safari选项被禁用?

后编辑:这是代码:

  function getSelectedValues(ids) { var selectedValues = [] , $selected = $('.selector').children('option:selected'); $selected.each(function(){ if(this.value != 0){ if(ids == true){ selectedValues.push(this.value+'-'+$(this).parent().attr('id')); } else { selectedValues.push(this.value); } } }); return selectedValues; } function clearDisabled() { $('.selector').children(':disabled').attr('disabled', false); } function disableSelected(selectedValues,id) { sv = selectedValues || []; if(id === true){ var selectedIds = []; var selectedVals = []; $.each(selectedValues, function(key, value) { values = value.split('-'); selectedVals.push(values[0]); selectedIds.push(values[1]); }); for (var i=0;i<selectedVals.length;i++) { $('.selector').each(function(){ if($(this).attr('id') == selectedIds[i]){ $('option[value=' + selectedVals[i] + ']',this).not(':selected').attr('disabled', true); } }); } } } $(document).ready(function(){ $('.selector').change(function(){ selectedValues = getSelectedValues(true); clearDisabled(); disableSelected(selectedValues, true); }); var selectedValues = getSelectedValues(true); disableSelected(selectedValues, true); }); 

我做了一些挖掘,我意识到这是safari mobile的限制……

 $("select option[disable='disable']").attr("disabled","disabled"); 

或者如果您使用的是jquery 1.6或更高版本

  $("select option[disable='disable']").prop("disabled",true); 

获得跨浏览器实现,iPad和iPhone的游戏,ie6更复杂,我认为其他一些浏览器只是忽略禁用的选项。

你需要删除它们。 因此,保留它的副本并随时重建选项。

这是一个示例,您可以根据其值启用/禁用选项

 var $select = $("select#myselect"); $select.data("copy", $select.find("option")) function disableOption($option) { var optionVal = $option.val(); $select.empty() $select.data("copy").each(function(){ var $currentOption = $(this); if (optionVal !== $currentOption.val() && $currentOption.attr("disabled")!=="disabled") $select.append($currentOption); else $currentOption.attr("disabled", "disabled"); }); } function enableOption($option) { var optionVal = $option.val(); $select.empty() $select.data("copy").each(function(){ var $currentOption = $(this); if (optionVal === $currentOption.val()) $currentOption.removeAttr("disabled") if ($currentOption.attr("disabled")!=="disabled") $select.append($currentOption); }); }