jQuery在firefox上运行不正常,而在Safari中根本没有运行

时间:2014-05-17 14:30:02

标签: javascript jquery jquery-ui firefox safari

我正在使用jQuery.unique()来摆脱Javascript数组中的double值。在Chrome中,它工作得很好,阵列的长度从60到29,在Firefox中它做了一些奇怪的事情,因为它从60到43,而在Safari中它根本不工作,任何提示? 这是我使用的进口:                 

  <title>APS</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <link href="../css/jquery-ui-1.10.4.css" rel="stylesheet">
  <link rel="stylesheet" href="../css/reset.css">
  <link href="http://s3.amazonaws.com/codecademy-content/courses/ltp/css/shift.css" rel="stylesheet">
    <link rel="stylesheet" href="http://s3.amazonaws.com/codecademy-content/courses/ltp/css/bootstrap.css">
  <script src="../js/jquery-1.10.2.js"></script>
  <script src="../js/jquery-ui-1.10.4.js"></script>
  <script src = "../js/search.js"></script>
  <link rel="stylesheet" href="../css/styles.css">
  <script type="text/javascript" src="http://www.parsecdn.com/js/parse-1.2.18.min.js"></script>

</head>

和js:

$(function() {
        Parse.initialize("T1S9kR0SEibdUjxpyOzaYccrGMVJmwOoaqclBDDO", "IiGFcSejnTIvfhTIEumgElGx9vru9MbdMora8SSZ");
    var query = new Parse.Query("pruebas");
    query.find({
            success: function(objects) {
        var centros=["VILLAVICIOSA", "EL VALLE", "PALOMERA", "ENCINAR", "SAN MATEO"];
        var tipos = ["Esporadico", "Semanal", "Esperando"];
        var nombres=[];
        var pruebas = ["Nacho", "Nacho ", "NACHO", "Nacho"];
        console.log(pruebas.length+pruebas);
        console.log(jQuery.unique(pruebas).length+jQuery.unique(pruebas));
        var emails=[];
        var dias = [];//"Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado", "Domingo"];
        var dnis=[];
        var i =0;
        objects.forEach(function(obj) {
                nombres[i] = obj.attributes.NOMBRE;
                emails[i] = obj.attributes.MAIL;
                dnis[i] = obj.attributes.DNI;
                dias[i] = obj.attributes.DIA;
                i++;
        });
        console.log("longitud de dias antes: "+dias.length);
        console.log("longitud de dias despues: "+jQuery.unique(dias).length);
        $('#nombres').focus();
        $( "#nombres" ).autocomplete({
            select: function( event, ui ) {console.log(ui.item.value);$('#emails').val('');$('#dnis').val('');
            $('#dias').val('');$('#centros').val('');$('#tipos').val('');},
            source: nombres,
            autoFocus: true
        });
        $( "#dias" ).autocomplete({
            select: function( event, ui ) {
                console.log(ui.item.value);
                console.log(
                objects.filter(function( obj ) {
                return obj.attributes.DIA == ui.item.value;
                }));
                $('#emails').val('');$('#dnis').val('');
            $('#nombres').val('');},
            source: jQuery.unique( dias ),
            autoFocus: true
        });
        $( "#emails" ).autocomplete({
            select: function( event, ui ) {console.log(ui.item.value);$('#centros').val('');$('#nombres').val('');$('#dnis').val('');
        $('#dias').val('');$('#tipos').val('');},
            source: emails,
            autoFocus: true
        });
        $( "#dnis" ).autocomplete({
            select: function( event, ui ) {console.log(ui.item.value);$('#centros').val('');$('#emails').val('');$('#nombres').val('');
        $('#dias').val('');$('#tipos').val('');},
            source: dnis,
            autoFocus: true
        });
        $( "#centros" ).autocomplete({
            select: function( event, ui ) {console.log(ui.item.value);$('#emails').val('');$('#nombres').val('');},
            source: centros,
            autoFocus: true
        });
        $( "#tipos" ).autocomplete({
            select: function( event, ui ) {console.log(ui.item.value);$('#emails').val('');$('#nombres').val('');},
            source: tipos,
            autoFocus: true
        });
            },
            error: function(error) {
                console.log("An error occured :(");
            }

        });

        $('#borrarBusq').click(function(){
            $('#nombres').val('');
            $('#emails').val('');
            $('#dnis').val('');
            $('#dias').val('');
            $('#tipos').val('');
            $('#centros').val('');
        });
    });

谢谢!

1 个答案:

答案 0 :(得分:0)

jQuery.unique仅适用于DOM元素:

  

描述:在适当的位置对DOM元素数组进行排序,并删除重复项。请注意,这仅适用于DOM元素的数组,而不适用于字符串或数字。

您需要实施自己的例程或使用lodashunderscore

之类的内容