如何使用 HTML 表单 [代码附加] 中的 GET 或 POST 从 javascript

如何使用 GET 或 POST 检索 CITY 值,就像可以使用 $_POST['stt'] 使用 STATE 值一样?


ps:堆栈溢出的新手,所以请建议更好的提问方式:)


var state_arr = new Array("Andaman & Nicobar");


var s_a = new Array();

s_a[0] = "";

s_a[1] = " Alipur | Andaman Island | Anderson Island | Arainj-Laka-Punga | Austinabad | Bamboo Flat | Barren Island ";


function print_state(state_id) {

  // given the id of the <select> tag as function argument, it inserts <option> tags

  var option_str = document.getElementById(state_id);

  option_str.length = 0;

  option_str.options[0] = new Option('Select State', '');

  option_str.selectedIndex = 0;

  for (var i = 0; i < state_arr.length; i++) {

    option_str.options[option_str.length] = new Option(state_arr[i], state_arr[i]);

  }

}


function print_city(city_id, city_index) {

  var option_str = document.getElementById(city_id);

  option_str.length = 0; // Fixed by Julian Woods

  option_str.options[0] = new Option('Select City', '');

  option_str.selectedIndex = 0;

  var city_arr = s_a[city_index].split("|");

  for (var i = 0; i < city_arr.length; i++) {

    option_str.options[option_str.length] = new Option(city_arr[i], city_arr[i]);

  }

}


print_state("sts");

<form>

  <select onchange="print_city('state', this.selectedIndex);" id="sts" name="stt" class="form-control" required></select>

  <select id="state" class="form-control" required></select>

</form>


POPMUISE
浏览 69回答 1
1回答

翻过高山走不出你

使用此功能,您将获得城市和州在表单操作属性中给出您的文件名var state_arr = new Array("Andaman & Nicobar");var s_a = new Array();s_a[0] = "";s_a[1] = " Alipur | Andaman Island | Anderson Island | Arainj-Laka-Punga | Austinabad | Bamboo Flat | Barren Island ";function print_state(state_id) {&nbsp; // given the id of the <select> tag as function argument, it inserts <option> tags&nbsp; var option_str = document.getElementById(state_id);&nbsp; option_str.length = 0;&nbsp; option_str.options[0] = new Option('Select State', '');&nbsp; option_str.selectedIndex = 0;&nbsp; for (var i = 0; i < state_arr.length; i++) {&nbsp; &nbsp; option_str.options[option_str.length] = new Option(state_arr[i], state_arr[i]);&nbsp; }}function print_city(city_id, city_index) {&nbsp; var option_str = document.getElementById(city_id);&nbsp; option_str.length = 0; // Fixed by Julian Woods&nbsp; option_str.options[0] = new Option('Select City', '');&nbsp; option_str.selectedIndex = 0;&nbsp; var city_arr = s_a[city_index].split("|");&nbsp; for (var i = 0; i < city_arr.length; i++) {&nbsp; &nbsp; option_str.options[option_str.length] = new Option(city_arr[i], city_arr[i]);&nbsp; }}print_state("sts");<form method="get" action="filename.html">&nbsp; <select onchange="print_city('state', this.selectedIndex);" id="sts" name="state" class="form-control" required></select>&nbsp; <select id="state" name="city" class="form-control" required></select>&nbsp; <input type="submit" value="submit"/></form>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript