ipad 禁用没有 jquery 的选择选项
有没有一种方法、插件或代码片段可以用来
<select><option disable="disable">....</option></select>
禁用 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 的限制...
There is a way,plugin or code snippet that i could use to make
<select><option disable="disable">....</option></select>
options in safari on ipad to be disabled ?
latter edit: here is the code:
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);
});
I did some digging and i realize that this is a limitation of safari mobile...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
获得跨浏览器的实现更加复杂,iPad和iPhone的safari,ie6和我认为其他一些浏览器只是忽略禁用的选项。
你需要删除它们。因此,保留一份副本并在需要时重建选项。
这是一个示例,您可以根据选项的值启用/禁用选项
It is more complicated to get a cross browser implementation, safari for iPad and iPhone, ie6 and I presume some other browser just ignore the disabled options.
You need to remove them. So, keep a copy of it and rebuild the options whenever you want.
This is an example where you can enable/disable options based on their value
或者如果您使用的是 jquery 1.6 或更高版本
or if you are using jquery 1.6 or higher