<select id="mySelect">
<option value="price">低价优先</option>
<option value="distance">距离优先</option>
</select>
<script>
var arr=[
{name:"肯德基",price:100,distance:100},
{name:"必胜客",price:200,distance:500},
{name:"华莱士",price:50,distance:1000},
]
var mySelect = document.getElementById("mySelect");
// onchange 输入框变化时触发事件
mySelect.onchange = function(){
console.log(this.value);
var value = this.value;
arr.sort(function(a,b){
return a[value]-b[value];
})
console.log(arr)
}
</script>