gpt4 book ai didi

javascript - JQuery 移动自定义水平单选按钮在实际设备中不起作用

转载 作者:行者123 更新时间:2023-11-29 10:18:44 30 4
gpt4 key购买 nike

最近我在 Stackoverflow 上问了一个问题,如何自定义水平 jQuery-mobile 单选按钮 您也可以从此链接查看帖子 How to customize horizontal jQuery-mobile radio buttons .一位开发人员用非常好的 JSFiddle 示例非常粗略地回答了这个问题。根据他的指示,我实现了自定义 JQuery Mobile 单选按钮,并且在桌面浏览器中一切正常。

然而,当我检查实际设备(Galaxy S 2、iPhone 5、Mac 模拟器和 Android 模拟器)时,它并没有像桌面浏览器那样工作。我不确定这里出了什么问题,但我可以理解我需要做一些小调整来支持实际设备。因此,我不擅长 JS,任何人都可以尽快研究一下。

这是 Gajotres 之前的 JSFiddle 示例 http://jsfiddle.net/Gajotres/779Kn/

$(document).on('pagebeforeshow', '#index', function(){     
$('<div>').addClass('checkBox').appendTo('fieldset div div.ui-radio label');
$('input[type="radio"]').each(function(){
($(this).is(':checked')) ? $(this).next().find(".checkBox").addClass('checked') : $(this).next().find(".checkBox").addClass('not-checked');
});

$(document).on('click', '.ui-radio', function(){
$('input[type="radio"]').each(function(){
$(this).next().find(".checkBox").addClass('not-checked').removeClass('checked');
});

if($(this).find('input[type="radio"]').is(':checked')){
$(this).find('label div.checkBox').removeClass('checked').addClass('not-checked');
$(this).find('input[type="radio"]').attr('checked' , false);
} else {
$(this).find('label div.checkBox').removeClass('not-checked').addClass('checked');
$(this).find('input[type="radio"]').attr('checked' , true);
}
});
});

.checkBox{
width: 18px;
height: 18px;
background: #d9d9d9;
border-radius: 3px;
margin: 0 auto;
margin-bottom: 5px;
}

.not-checked, .checked {
background-image: url("http://www.fajrunt.org/icons-18-white.png");
background-repeat: no-repeat;
}

.not-checked {
background-position: -18px 0;
background-color:#d9d9d9;
}

.checked {
background-position: -720px 0;
background-color:#6294bc;
}

我创建了一个单独的链接,希望这能帮助您快速检查设备。 http://www.apartmentslanka.com/ztest_calender/radio.html

*Stackoverflow 仅供引用:我尝试从之前的帖子继续,但由于负责任的开发人员无法回答或检查上一期,我创建了一个新帖子。

最佳答案

你真的需要耐心等待,我正在度假:)

这是一个工作示例:http://jsfiddle.net/Gajotres/779Kn/20/

这个版本应该适用于触摸设备和桌面浏览器:http://jsfiddle.net/Gajotres/779Kn/21/

Click 事件已更改为 touchstart 事件,现在它也适用于移动设备。

$(document).on('pagebeforeshow', '#index', function(){     
$('<div>').addClass('checkBox').appendTo('fieldset div div.ui-radio label');
$('input[type="radio"]').each(function(){
($(this).is(':checked')) ? $(this).next().find(".checkBox").addClass('checked') : $(this).next().find(".checkBox").addClass('not-checked');
});

$(document).on('touchstart', '.ui-radio', function(){
$('input[type="radio"]').each(function(){
$(this).next().find(".checkBox").addClass('not-checked').removeClass('checked');
});

if($(this).find('input[type="radio"]').is(':checked')){
$(this).find('label div.checkBox').removeClass('checked').addClass('not-checked');
$(this).find('input[type="radio"]').attr('checked' , false);
} else {
$(this).find('label div.checkBox').removeClass('not-checked').addClass('checked');
$(this).find('input[type="radio"]').attr('checked' , true);
}
});
});

关于javascript - JQuery 移动自定义水平单选按钮在实际设备中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15756333/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com