-3

私はjavascriptを勉強していて、開始アドレスと宛先アドレスを要求するフォームを作成しています。私がやりたいこと-しかし、理解できない-入力ボックスの場合に2つの値を比較する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       ";
}

例 : 開始点がポイント 1 で終了点がポイント 2 の場合は、「タクシーに乗る」と表示されます。開始点がポイント 1 と終了点がポイント 3 の場合は、「バスに乗るだけ」と表示されます。

4

1 に答える 1

0
function printme() {
    var start = document.getElementById('start').value;
    var end = document.getElementById('end').value;

    if (start !== end) {
        alert("can't go there!");
    } else {
        alert("you must ride a " + start.split(' ')[0]); // appends the first word entered into the input
    }
}
于 2013-09-27T17:22:59.067 に答える