我正在学习 javascript,我正在制作一个表格,它将要求输入起始地址和目标地址。我想要做的 - 但无法弄清楚 - 如果我的输入框并且如果它存在于函数中它将显示一条消息,但如果它不存在它仍然会循环直到它找到值并显示消息或如果它真的没有任何东西则显示错误。
基于此 HTML 表单:
<div id="panel">
<form>
<input type="text" placeholder="Start Address" id="start" >
<input type="text" placeholder="Destination Address" id="end">
<input type="button" value="Get Direction" id="SubmitBtn" onclick="printme()" >
</form>
</div>
<div id="infopanel">
</div>
function printme(){
var start = document.getElementById("start").value;
var end = document.getElementById("end").value;
var point1="point1";
var point2="point2";
var point3"point3";
if (start==point1&&end==point2){
document.getElementById("infopanel").innerHTML="point1 to point2 just ride a taxi";
}
else if (start==point1&&end==point3){
document.getElementById("infopanel").innerHTML="point1 to point3 just ride a bus";
}
else document.getElementById("infopanel").innerHTML="no route found we will update you ";
}
示例:如果 start 等于 point1 并且 end 等于 point2 则显示“只需乘坐出租车” 否则如果 start 等于 1 点并且 end 是 point3 则显示“只需乘坐公共汽车” else 显示“找不到路线我们会更新你”