如何用Java脚本以表格的形式展现城市的状态?

时间:2020-11-14 作者:Rahul Kumar

我正在研究Contact Form 7 我想在联系表7中展示各州的城市。

我也使用了插件,但它不是根据条件工作,我不想在国家字段中。这就是为什么我要尝试自己的代码。

I cant ask this question in Contact Form 7 Forum because this is developer need and it requires some JavaScript knowledge.

My Code:

[select* your-state first_as_label "Select Your State*" "Andaman and Nicobar Islands" "Andhra Pradesh" "Arunachal Pradesh" "Assam" "Bihar" "Chandigarh" "Chhattisgarh" "Dadra and Nagar Haveli" "Daman and Diu" "Delhi" "Goa" "Gujarat" "Haryana" "Himachal Pradesh" "Jammu and Kashmir" "Jharkhand" "Karnataka" "Kerala" "Ladakh" "Lakshadweep" "Madhya Pradesh" "Maharashtra" "Manipur" "Meghalaya" "Mizoram" "Nagaland" "Odisha" "Puducherry" "Punjab" "Rajasthan" "Sikkim" "Tamil Nadu" "Telangana" "Tripura" "Uttar Pradesh" "Uttarakhand" "West Bengal"]

[select* your-city first_as_label "Select Your City*"]
我有城市列表:https://github.com/ajayrandhawa/Indian-States-Cities-Database

非常感谢您的帮助。

1 个回复
最合适的回答,由SO网友:Rahul Kumar 整理而成

我找到了解决办法。

Just Add This Code In Contact Form 7:

<select name="stt" id="sts" class="form-control"  required="" onchange="print_city(\'state\', this.selectedIndex);"></select>
<select name="city" id="state" class="form-control" required=""></select>
<script language="javascript">print_state("sts");</script>
这个在Functions.php

function my_theme_scripts_function() {
   wp_enqueue_script( \'myscript\', get_template_directory_uri() . \'/cities.js\');
}
add_action(\'wp_enqueue_scripts\',\'my_theme_scripts_function\'); 
你可以选择城市。此处的js文件:https://github.com/ajayrandhawa/Indian-States-Cities-Database

In this, you can add cities you want.

For The Mail:

State: [stt]
City: [city]
这就是解决方案。