Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/428.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何仅在设备基于iOS时运行jQuery代码?_Javascript_Jquery_Html_Ios - Fatal编程技术网

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
            });
        });
    }
});