javascript - js wrong string output -
i need correct valeu string, done wrong ?
var = 0; var ret = '<option value="19">dep_01_01</option><option value="20">dep_01_02</option>'; var pre = ret + '<option value="0">non</option>'; var count = $($.parsehtml(pre)).filter('option').length; console.log(pre); for(i=0; < count; i++){ var val_drop = $($.parsehtml(pre)).filter("option[value*='" + + "']").val(); var text_drop = $($.parsehtml(pre)).filter("option[value*='" + + "']").text(); console.log(val_drop); }
the output :
<option value="19">dep_01_01</option><option value="20">dep_01_02</option><option value="0">non</option> 20 19 20
but correct output should be:
19 20 0
you dont need function that
var ret = '<option value="19">dep_01_01</option><option value="20">dep_01_02</option>'; var pre = ret + '<option value="0">non</option>'; $(pre).each(function(){ $('#result').append($(this).val()+" <-----> "+$(this).html()+"<br>"); })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="result">
Comments
Post a Comment