我有这个 html 代码部分
<div id="prt">
<select name="selectPrt" class="span12" onchange="sta_callPRT();">
<option value="noPrt">Choose one vehicle.</option>
<option value="prt1">PRT 1</option>
<option value="prt2">PRT 2</option>
<option value="prt3">PRT 3</option>
<option value="prt4">PRT 4</option>
<option value="prt5">PRT 5</option>
</select>
<div class="row-fluid">
<div class="span6">
<div class="section">
<div class="sectionTitle">
<h3>Vehicle Info</h3>
</div>
</div>
<div id="state"><strong>State:</strong> </div>
<div id="freeSeats"><strong>freeSeats:</strong></div>
<div id="battery"><strong>battery:</strong></div>
<div id="totalDistance"><strong>totalDistance:</strong></div>
<div id="location"><strong>Location:</strong></div>
<div id="estimatedTime"><strong>estimatedTime"</strong></div>
<div id="estimatedDistance"><strong>estimatedDistance:</strong></div>
<div id="speed"><strong>speed:</strong></div>
而这个 Javascript
function sta_callPRT(){
$.getJSON('PRTInfoGenerator.php', function(json){
$.each(json, function(key, value) {
if(key=="state") {
//$('#state').empty();
//document.getElementById("parameters").appendChild(divTag);
$('#state').append(value);
}
if(key=="freeSeats") {
$('#freeSeats').append(value);
}
if(key=="estimatedDistance"){
$('#estimatedDistance').append(value);
}
if(key=="estimatedTime"){
$('#estimatedTime').append(value);
}
if(key=="battery"){
$('#battery').append(value);
}
if(key=="speed"){
$('#speed').append(value);
}
if(key=="location"){
$.each(json.location, function(par_key, par_value) {
$('#location').append(par_key+': '+par_value+' ');
});
}
if(key=="totalDistance"){
$('#totalDistance').append(value);
}
});
});
}
我想在 html 中随机写入车辆值。我还有 php 代码来为车辆生成随机值。当我选择车辆时,它会显示一些值,但在第二次选择中,新值被添加到第一个的末尾。如何删除以前的值,并在进行新选择时添加新值?例如这是网页中的第一个选择;
State: Running
freeSeats:0
battery:95
totalDistance:8541
Location:x: -5 y: 34
estimatedTime:15
estimetedDistance:809
Speed:18
这是第二个;
State: RunningRunning
freeSeats:04
battery:9540
totalDistance:85411848
Location:x: -5 y: 34 x: 84 y: -70
estimatedTime:15269
estimetedDistance:809513
Speed:1818