- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我发现了一个很棒的教程,用于创建可以动态更改的下拉菜单。
这是链接。
这是演示
http://roshanbh.com.np/dropdown/
<小时/>我稍微摆弄了一下代码,并跳过了您选择状态的部分。
这是 findCity.php 文件
<!--//---------------------------------+
// Developed by Roshan Bhattarai |
// http://roshanbh.com.np |
// Contact for custom scripts |
// or implementation help. |
// email-nepaliboy007@yahoo.com |
//---------------------------------+-->
<?
#### Roshan's Ajax dropdown code with php
#### Copyright reserved to Roshan Bhattarai - nepaliboy007@yahoo.com
#### if you have any problem contact me at http://roshanbh.com.np
#### fell free to visit my blog http://php-ajax-guru.blogspot.com
?>
<? $country = $_GET['country'];
$link = mysql_connect("snip","snip","snip");
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('snip');
$query="SELECT city FROM location WHERE country='$country'";
$result=mysql_query($query);
?>
<select name="city">
<option>Select City</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value><?=$row['city']?></option>
<? } ?>
</select>
使用国家/地区变量打开 findCity.php 效果很好
http://globatum.com/admin/findCity.php?country=United%20States
我无法弄清楚为什么国家/地区列表中的值没有正确通过此函数
function getCity(country) {
var strURL="findCity.php?country="+ country;
var req = getXMLHTTP();
if (req) {
req.onreadycountrychange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('citydiv').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
这里有什么想法吗?
添加注释
function getXMLHTTP() { //function to return the xml http object
var xmlhttp=false;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e) {
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}
return xmlhttp;
}
最佳答案
您的页面上有一个 javascript 错误,@nevermind 抢先我指出了这一点。没关系,但是您还有另一个问题,这似乎只是您的误解。线路
req.onreadycountrychange = function() {
没有意义,需要改为:
req.onreadystatechange = function() {
函数的名称onreadystatechange
在这种情况下有点令人困惑,但它与“州/国家”中的“州”没有任何关系。这是指 XMLHttpRequest 对象的当前状态。基本上,每当请求对象的状态更新时,就会调用该函数 onreadystatechange
。
在这里阅读更多相关信息:http://www.w3schools.com/ajax/ajax_xmlhttprequest_onreadystatechange.asp
关于php - Ajax 乡村城市选择菜单 onChange() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17496557/
from django.db import models from django.core.urlresolvers import reverse from django.conf import se
我是一名优秀的程序员,十分优秀!