![](/img/trans.png)
[英]This javascript works in every browser EXCEPT for internet explorer!
[英]logic that works on every browser/device except samsung internet
我有一段代码可以用在三星Internet以外的所有产品上。 Chrome移动版和chrome开发工具移动仿真器都可以正常工作。 我每次尝试都会清除浏览数据。
单击服务类别按钮时(下面的第一张图片),它应该打开相关的引导折叠卡(下面的第二张图片)。
第一张图片:
第二张图片:
这是github仓库https://github.com/dByler1/windle-chimney https://dbyler1.github.io/windle-chimney/
.on('click',function(){})的工作原理。每个变量的日志记录都很干净,只是不会进入逻辑块。
$(".servicesBTN").on("click", function (e) {
//get the data target value of the button that was clicked which is the same as the accordian content IDs
let dataTarget = this.getAttribute("data-target")
let servicesDisplayValue = getComputedStyle(document.getElementById('servicesDescriptions')).display
//all three console.logs fire and log expected results
console.log('data target ' + dataTarget)
console.log('services display value ' + servicesDisplayValue)
console.log('test hasClass' + $(dataTarget).hasClass('show'))
//if the clicked button's associated card does have the show class, set the data toggle to blank so it won't change
//none of the logs in the if blocks fire
if ($(dataTarget).hasClass("show") && servicesDisplayValue === 'block') {
this.setAttribute("data-toggle", "")
console.log('first block - already open - display block')
} else if ($(dataTarget).hasClass("show") && servicesDisplayValue === 'none') {
this.setAttribute("data-toggle", "")
mobileShowServiceInfo($(this))
console.log('second block - already open - display none - mobile assumption')
}
else {
//give the clicked button a data-toggle of collapse so it will open
this.setAttribute("data-toggle", "collapse")
mobileShowServiceInfo($(this))
changeAllAngleIcons($(this))
console.log('third block - ')
}
})
这是关于您与Samsung Internet( SI )有关的问题根源的一个假设。
首先,问题出在函数调用中: mobileShowServiceInfo($(this))
。 不在if / else块中。
在该函数中,存在以下问题:( 来自OP的GitHub存储库 )
document.getElementById('backBTN').classList.replace('d-none', 'd-md-none')
所以我想SI 真的不喜欢 .replace()
的未分配结果。
这可能应该工作:
let tempClassList = document.getElementById('backBTN').classList;
document.getElementById('backBTN').classList = tempClassList.replace('d-none', 'd-md-none');
但这虽然简短明了,却解决了这个问题:
$('#backBTN').removeClass('d-none').addClass('d-md-none');
所以我想 SI不会破坏代码而不是因为没有赋值而直接放弃.replace()
结果,而是破坏了代码...
;
在每行代码的末尾。
在这个SO答案中有更多关于它的阅读。
;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.