将我的数据放在每个不同的选项标签

时间:2017-07-06 01:23:58

标签: javascript json function api onchange

问题是我从webservice获取数据,干净如字符串但是在我想将数据放入选项标签的那一刻,结果是

<select>
 <option>data1data2data3data4data5</option>
</select>

我想要

<select>
 <option>data1/option>
 <option>data2</option>
 <option>data3</option>
 <option>data4</option>
 <option>data5</option>
</select>

我正在使用onchange javascript事件从我的webservice获取我想要的数据。 我的代码:

    <script type="text/javascript">
    function fill(ent) {
        var jsonCl , i, x = "";
        var tagoption = $('#cC');
        var jsonCl = JSON.parse( '<?php print json_encode($totaljson); ?>' );
        if ( jsonCl.estado== '1') {
            for(var i =0; i < jsonCl.hospital.length; i++) {
                var split = jsonCl.hospital[i].nombre_hospital.split(",");

$(“#cC”)。html('..:HOSPITALS:..'+ hospital +'');

               if(jsonCl.hospital[i].entidad == ent) {
                   var hospital =  x += split + "<br>"+ "<br>";
                   var latlon = jsonCl.clinicas[i].latlon;
                   var num_hospital = jsonCl.clinicas[i].num_clinica;
                   var delmpio = jsonCl.clinicas[i].delmpio;
                   var nombre_hospital = jsonCl.hospital[i].nombre_hospital;
                   var direccion = jsonCl.hospital[i].direccion;
                   var entidad = jsonCl.hospital[i].entidad;
                   var ref1 = jsonCl.hospital[i].referencia1;
                   var ref2 = jsonCl.hospital[i].referecnia2;
                    }
                    else if(entidad == 'undefined' ){
                        entidad = x;

                    }  
                }



                     console.log(latlon)  
                     console.log(num_hospital) 
                     console.log(delmpio) 
                     console.log(nombre_hospital) 
                     console.log(direccion) 
                     console.log(entidad) 
                     console.log(ref1) 
                     console.log(ref2) 
    }
    else {
        console.log('Not state')
        }

    }
    </script>

0 个答案:

没有答案