如何从外部js文件显示此特定下拉列表(国家和地区)??在带有select和option标签的常规HTML表单中,它可以很好地工作,但是当使用php时它不会.js文件位于我正在使用的某个文件夹中,并且它在常规html文件中正常工作。使用PHP它不会运行。不知何故,似乎无法使用select和option
调用php中的.js文件<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
</style>
<body>
<form action="" method="POST">
Select Country (with states):
<select id="country" name="country" required></select>
<br>State:
<select name="region" id="region" required></select>
<br>
<input type="submit" name="submit" value="Registros">
<script src="locations.js"></script>
<script src="locations2.js" language="javascript"></script>
</form>
</head>
<?php
if(isset($_POST['submit'])){
echo "<tr><form action='' method='POST'>";
echo "<td><select name='technology'><option>ERP/CRM/EPM/BI</option><option>Cyber Security</option><option>Networking</option><option>Infrastructure</option><option>Big Data/M2M/IoT/Blockchain</option><option>Physical Security</option></select></td>";
echo "<td><select name='description'><option>VENDOR</option><option>VAD</option><option>VAR</option><option>CUSTOMER</option></td>";
echo "<td><select id='country' name='country'><option><script src='locations.js'></script></option></select></td>";
echo "<td><select id='region' name='region'><option><script src='locations2.js'></script></option></select></td>";
echo"</form></tr>";
}
?>
</body>
</html>
答案 0 :(得分:0)
您可以使用国家/地区库来简化开发,而不是2个javascript。查看这个免费的库:https://github.com/geodatasource/country-region-dropdown-menu。托管图书馆可用,如果需要,您无需在本地参考。
<html>
<head>
<meta charset="UTF-8">
<script src="//cdnjs.cloudflare.com/ajax/libs/country-region-dropdown-menu/1.1.0/geodatasource-cr.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="dist/geodatasource-countryflag.css">
</head>
<body>
<div>
Country: <select class="gds-cr" country-data-region-id="gds-cr-one" ></select>
Region: <select id="gds-cr-one" ></select>
</div>
</body>
</html>