0

所以我有一个关于火车站的连锁选择。人们必须选择他们的起点和目的地。

<form action="#" id="routeform" method="GET">
  <select class="station" name="station">
    <option value="Antwerpen">Antwerpen-Centraal</option>
    <option value="Bergen">Bergen</option>
    <option value="Brugge">Brugge</option>
    <option value="Brussel">Brussel</option>
    <option value="Charleroi">Charleroi-Zuid</option>
    <option value="DePanne">De Panne</option>
    <option selected="selected" value="Gent">Gent-Sint-Pieters</option>
    <option value="Hasselt">Hasselt</option>
    <option value="Kortrijk">Kortrijk</option>
    <option value="Leuven">Leuven</option>
    <option value="Luik">Luik-Guillemins</option>
    <option value="Namen">Namen</option>
    <option value="Oostende">Oostende</option>
    <option value="Roeselare">Roeselare</option>
  </select>
  <select class="series" name="series">
    <option value="">--</option>
    <option value="Antwerpen" class="Gent">Antwerpen-Centraal</option>
    <option value="Bergen" class="Gent">Bergen</option>
    <option value="Brugge" class="Gent">Brugge</option>
    <option value="Brussel" class="Gent">Brussel</option>
    <option value="Charleroi" class="Gent">Charleroi-Zuid</option>
    <option value="DePanne" class="Gent">De Panne</option>
    <option value="Hasselt" class="Gent">Hasselt</option>
    <option value="Kortrijk" class="Gent">Kortrijk</option>
    <option value="Leuven" class="Gent">Leuven</option>
    <option value="Luik" class="Gent">Luik-Guillemins</option>
    <option value="Namen" class="Gent">Namen</option>
    <option value="Oostende" class="Gent">Oostende</option>
    <option value="Roeselare" class="Gent">Roeselare</option>
    <option value="Gent" class="Antwerpen">Gent-Sint-Pieters</option>
    <option value="Brugge" class="Kortrijk">Brugge</option>
    <option value="Gent" class="Kortrijk">Gent-Sint-Pieters</option>
    <option value="Roeselare" class="Kortrijk">Roeselare</option>
    <option value="Gent" class="Brugge">Gent-Sint-Pieters</option>
    <option value="Kortrijk" class="Brugge">Kortrijk</option>
    <option value="Oostende" class="Brugge">Oostende</option>
    <option value="Roeselare" class="Brugge">Roeselare</option>
    <option value="Brugge" class="Oostende">Brugge</option>
    <option value="Gent" class="Oostende">Gent-Sint-Pieters</option>
    <option value="Brussel" class="Bergen">Brussel</option>
    <option value="Gent" class="Bergen">Gent-Sint-Pieters</option>
    <option value="Brussel" class="Namen">Brussel</option>
    <option value="Gent" class="Namen">Gent-Sint-Pieters</option>
    <option value="Bergen" class="Brussel">Bergen</option>
    <option value="Charleroi" class="Brussel">Charleroi-Zuid</option>
    <option value="Gent" class="Brussel">Gent-Sint-Pieters</option>
    <option value="Hasselt" class="Brussel">Hasselt</option>
    <option value="Leuven" class="Brussel">Leuven</option>
    <option value="Luik" class="Brussel">Luik-Guillemins</option>
    <option value="Namen" class="Brussel">Namen</option>
    <option value="Brussel" class="Leuven">Brussel</option>
    <option value="Gent" class="Leuven">Gent-Sint-Pieters</option>
    <option value="Hasselt" class="Leuven">Hasselt</option>
    <option value="Luik" class="Leuven">Luik-Guillemins</option>
    <option value="Brussel" class="Hasselt">Brussel</option>
    <option value="Gent" class="Hasselt">Gent-Sint-Pieters</option>
    <option value="Leuven" class="Hasselt">Leuven</option>
    <option value="Brussel" class="Charleroi">Brussel</option>
    <option value="Gent" class="Charleroi">Gent-Sint-Pieters</option>
    <option value="Brussel" class="Luik">Brussel</option>
    <option value="Gent" class="Luik">Gent-Sint-Pieters</option>
    <option value="Leuven" class="Luik">Leuven</option>
    <option value="Gent" class="DePanne">Gent-Sint-Pieters</option>
    <option value="Brugge" class="Roeselare">Brugge</option>
    <option value="Gent" class="Roeselare">Gent-Sint-Pieters</option>
    <option value="Kortrijk" class="Roeselare">Kortrijk</option>
  </select>
  <br/>
  <input type="submit" value="Go" />
</form>

每个结果都有一个不同的 html.page 它必须去。我试过这个例如(从安特卫普到根特):

$('#routeform').submit(function () {
  if ($('select.station').val() == 'Antwerpen') && ($('select.series').val() == 'Gent') {
    window.open("contact.html", "_self");
  }
  return false;
});

但它不起作用,我找不到问题......

提前致谢!

4

1 回答 1

0

尝试这个 :

$('#routeform').submit(function (evt) {
  if (($('select.station').val() == 'Antwerpen') && ($('select.series').val() == 'Gent')) {
    window.open("contact.html", "_self");
  }
  evt.preventDefault(); // this prevents the submit
});

你的括号不正确

或者

if ($('select.station').val() == 'Antwerpen' && $('select.series').val() == 'Gent') {

因为您不必将语句包含if在括号内 - 它仍然有效

这里的工作示例

于 2012-06-09T19:45:16.003 回答