如何制作网站目的地的表单输入部分?

时间:2016-08-30 23:00:24

标签: javascript html

我有一个用html制作的选择表单,我想在提交时将所选值作为url目标的一部分。 例如:

<form>
<select name="state" id="state">
              <option value="AK">Alaska</option>
              <option value="AL">Alabama</option>
              <option value="AR">Arkansas</option>
              <option value="AZ">Arizona</option>
              <option value="CA">California</option>
    </select>
<input type="submit" value="submit">
</form>

当他们选择时,我们说“CA”,我希望提交按钮转到“www.example.com/ca.html”。

这是我的JS:

var stLocation = document.getElementById("state").value;
  window.location.href = 'www.example.com/stLocation.html';

1 个答案:

答案 0 :(得分:1)

首先,您需要将 jQuery库包含在脚本中。然后你试试这个

.....
    final KategoriAdapter adapter = new KategoriAdapter(getApplicationContext(), mKategoriler, kategoriResimleri);
    grid=(GridView)findViewById(R.id.gv_kategoriler);
    grid.setAdapter(adapter);
    grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            adapter.useNewTemplate(position);
            Toast.makeText(getApplicationContext(), mKategoriler[position].toString(),Toast.LENGTH_SHORT).show();
        }
    });

}

但如果它在$('button').click(function (){ selectedValue = $('select').val().toLowerCase(); //I converted it to lowercase due to the case difference in your value and your url window.location.href = "http://www.example.com/"+selectedValue+".html"; }); 标签中,请改用

form