Javascript 如何仅在设备基于iOS时运行jQuery代码?
可能重复:Javascript 如何仅在设备基于iOS时运行jQuery代码?,javascript,jquery,html,ios,Javascript,Jquery,Html,Ios,可能重复: 以下是我想做的: <script type="text/javascript"> // Run This code if device is iOS based window.addEventListener('DOMContentLoaded',function() { $("body").queryLoader2({ barColor: "#37201b",
以下是我想做的:
<script type="text/javascript">
// Run This code if device is iOS based
window.addEventListener('DOMContentLoaded',function() {
$("body").queryLoader2({
barColor: "#37201b",
backgroundColor: "#c2a875",
percentage: true,
barHeight: 5,
completeAnimation: "grow"
});
});
// if it is not iOS run this code
$(document).ready(function () {
$("body").queryLoader2({
barColor: "#37201b",
backgroundColor: "#c2a875",
percentage: true,
completeAnimation: "grow",
barHeight: 5
});
});
</script>
//如果设备基于iOS,请运行此代码
addEventListener('DOMContentLoaded',function(){
$(“正文”).queryLoader2({
barColor:#37201b“,
背景色:#c2a875“,
百分比:正确,
酒吧高度:5,,
完整化:“成长”
});
});
//如果不是iOS,请运行此代码
$(文档).ready(函数(){
$(“正文”).queryLoader2({
barColor:#37201b“,
背景色:#c2a875“,
百分比:正确,
完成动画:“成长”,
酒吧高度:5
});
});
与其说是评论,不如说我写些什么来让它工作?更好的问题:为什么你只想让它在iOS上运行,你应该使用功能检测而不是操作系统检测?@Blazemonger否,我只需要部分来检测iOS
jQuery(document).ready(function($){
var deviceAgent = navigator.userAgent.toLowerCase();
var agentID = deviceAgent.match(/(iPad|iPhone|iPod)/i);
if (agentID) {
window.addEventListener('DOMContentLoaded',function() {
$("body").queryLoader2({
barColor: "#37201b",
backgroundColor: "#c2a875",
percentage: true,
barHeight: 5,
completeAnimation: "grow"
});
});
}
else
{
$(document).ready(function () {
$("body").queryLoader2({
barColor: "#37201b",
backgroundColor: "#c2a875",
percentage: true,
completeAnimation: "grow",
barHeight: 5
});
});
}
});