选择x + y然后返回文本字符串

Select x + y then return text string

本文关键字:返回 文本 字符串 然后 选择      更新时间:2023-09-26

我有九个不同的预先编写的文本字符串,表示特定旅行路线的时间和成本。变量是旅程的起点和终点。

我希望用户在表单中选择两个变量,并使用Javascript获得对应于旅程起点和终点的结果文本字符串。

<table>
  <tr>
    <td><p>&nbsp;</p>
      <form id="route_details" name="route_details" method="post">
        <p>
          <label for="start">Departure Location:</label>
          <select name="start" id="start">
            <option>a</option>
            <option>b</option>
            <option>c</option>
</select>
          <label for="end">Arrival Location:</label>
          <select name="end" id="end">
            <option>e</option>
            <option>f</option>
            <option>g</option>
</select>
       </p>
        <p>RESULT STRING: 00:00 - $0,000.00</p>
      </form>
   </td>
  </tr>
</table>

这里是使用jQuery。你的问题很不清楚,所以我只列举了一般情况。

$('select').change(function() {
    var first = parseInt($('#1').val());
    var second = parseInt($('#2').val());
    $('.result').html(first + second);
});

JSFiddle