Php 因为一个瀑布式下降而流汗和尖叫
为了解决我的问题,我花了大约五天的时间寻找答案,我想我还是寻求一些帮助为好。我正在做一个层叠式下拉列表,我似乎无法开始工作 Mysql数据保存在一个表中,其中包含国家(varchar)和地区(varchar)、文档名称(varchar)、文档链接(varchar)以及添加的日期(时间戳) 我希望第一个下拉列表指向包含区域的第二个下拉列表。我看了很多教程,但我似乎找不到一个既使用PDO又使用Mysqli的教程。提交表单时,我希望文档的名称显示为超链接,并添加日期 我开始使用: 这是我的代码: “下拉式网站” 函数文件(blanked_func2.php)Php 因为一个瀑布式下降而流汗和尖叫,php,jquery,mysql,json,cascadingdropdown,Php,Jquery,Mysql,Json,Cascadingdropdown,为了解决我的问题,我花了大约五天的时间寻找答案,我想我还是寻求一些帮助为好。我正在做一个层叠式下拉列表,我似乎无法开始工作 Mysql数据保存在一个表中,其中包含国家(varchar)和地区(varchar)、文档名称(varchar)、文档链接(varchar)以及添加的日期(时间戳) 我希望第一个下拉列表指向包含区域的第二个下拉列表。我看了很多教程,但我似乎找不到一个既使用PDO又使用Mysqli的教程。提交表单时,我希望文档的名称显示为超链接,并添加日期 我开始使用: 这是我的代码: “下
我正在使用jQuery版本1.9.1,如有任何帮助,将不胜感激
/Sten问题在于Javascrip。从Jquery 1.9开始,live已更改为.on。 正确的Jquery代码是:
var formObject = {
run : function(obj) {
if (obj.val() === '') {
obj.nextAll('.update').html('<option value="">----</option>').attr('disabled', true);
} else {
var id = obj.attr('id');
var v = obj.val();
jQuery.getJSON('func/blankett_func.php', { id : id, value : v }, function(data) {
if (!data.error) {
obj.next('.update').html(data.list).removeAttr('disabled');
} else {
obj.nextAll('.update').html('<option value="">----</option>').attr('disabled', true);
}
});
}
}
};
$(function() {
$('.update').on('change', function() {
formObject.run($(this));
});
});
var formObject={
运行:功能(obj){
if(obj.val()=''){
obj.nextAll('.update').html('---').attr('disabled',true);
}否则{
var id=obj.attr('id');
var v=obj.val();
getJSON('func/blankett_func.php',{id:id,value:v},函数(数据){
如果(!data.error){
obj.next('.update').html(data.list).removeAttr('disabled');
}否则{
obj.nextAll('.update').html('---').attr('disabled',true);
}
});
}
}
};
$(函数(){
$('.update')。在('change',function()上{
运行($(this));
});
});
您的选项实际上都没有值。您是否建议创建两个单独的表,其中区域和国家将具有相应的值(id)。如果这是一个愚蠢的问题,我很抱歉,但这对我来说是全新的。这个例子似乎让它在没有id的情况下工作。
function popregion() {
$.getJSON('/blanketter_func2.php', {countryname:$('#countryname').val()}, function(data) {
var select = $('#regionname');
var options = select.prop('options');
$('option', select).remove();
$.each(data, function(index, array) {
options[options.length] = new Option(array['region']);
});
});
}
$(document).ready(function() {
popregion();
$('#countryname').change(function() {
popregion();
});
});
<?php
$dsn = "mysql:host=localhost;dbname=blanketter";
$username = "root";
$password = "root";
$pdo = new PDO($dsn, $username, $password);
$rows = array();
if(isset($_GET['countryname'])) {
$stmt = $pdo->prepare("SELECT region FROM blanketter WHERE country = ? ORDER BY region");
$stmt->execute(array($_GET['countryname']));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
echo json_encode($rows);
?>
var formObject = {
run : function(obj) {
if (obj.val() === '') {
obj.nextAll('.update').html('<option value="">----</option>').attr('disabled', true);
} else {
var id = obj.attr('id');
var v = obj.val();
jQuery.getJSON('func/blankett_func.php', { id : id, value : v }, function(data) {
if (!data.error) {
obj.next('.update').html(data.list).removeAttr('disabled');
} else {
obj.nextAll('.update').html('<option value="">----</option>').attr('disabled', true);
}
});
}
}
};
$(function() {
$('.update').on('change', function() {
formObject.run($(this));
});
});