我在HTML中创建一个复选框,如下所示:
<input type="checkbox" name="vehicle" value="Bike" /> I have a bike<br />
现在,我想要I have a bike
部分,即除了复选框之外的文本来自变量。怎么办呢?
答案 0 :(得分:5)
<input type="checkbox" name="vehicle" value="Bike" id="vehicle" />
<label for="vehicle" id="lblVehicle"></label><br />
<script>
var lblBike = 'I have a bike';
document.getElementById('lblVehicle').innerHTML = lblBike;
</script>
答案 1 :(得分:1)
var yourTextVariable = 'I have a cool bike';
document.getElementById('vehicle').innerHTML = yourTextVariable;