我有这个jquery代码片段。因为它没有传递给我值,所以我尝试了各种方法来找出原因,包括函数回调来查看发生了什么。然而,没有显示任何内容。两个不同的例子
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
//jquery code for source list
$(document).ready(function()
{
$('#country').change(function()
{
if ($(this).val()!='')
{
$("#source").load("/CI-3/application/controllers/control_form.php", {pais_id: $(this).val()}, function()
{
alert('Load was not performed.'));
}
});
}); // end of country and city function
</script>因此,这是应该在更改值时激活jquery的selectlist:
<?php echo form_open('control_form/add_all'); ?>
<label for="country">Country<span class="red"></span></label>
<select id="country" name="country">
<option value="">Select</option>
<?php
foreach($result as $row)
{
echo '<option value="' . $row->pais_id . '">' . $row->pais_name . '</option>';
}
?>
</select>还有一个不同的例子:
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$('#country').change(function()
{
if ($(this).val()!='')
{
$("#loquesea").load("/not-here.php", function(response, status, xhr)
{
if (status == "error")
{
var msg = "Sorry but there was an error: ";
$("#error").html(msg + xhr.status + " " + xhr.statusText);
}
});
});
});
});
</script>
</head>
<body>
<b>Successful Response (should be blank):</b>
<div id="success"></div>
<b>Error Response:</b>
<div id="error"></div>
<form action="">
<select id = "country" name="country">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
</form>
</body>发布于 2012-08-13 21:15:04
您的html中没有带id源的元素,因此您的选择器将为$("#source")
变化
$("#source")至
$("#success")if ($(this).val() != ''){缺少}括号
$(document).ready(function() {
$('#country').change(function() {
if ($(this).val() != '') {
$("#loquesea").load("/not-here.php", function(response, status, xhr) {
if (status == "error") {
var msg = "Sorry but there was an error: ";
$("#error").html(msg + xhr.status + " " + xhr.statusText);
}
});
}
});
});发布于 2012-08-13 21:14:31
括号有很多错误。修复它们,你的代码就会正常工作。使用正确的缩进作为指导。
$(document).ready(
function()
{
$('#country').change(
function()
{
if ($(this).val()!='')
{
$("#source").load("/CI-3/application/controllers/control_form.php",
{pais_id: $(this).val()},
function()
{
alert('Load was not performed.'); // 1st fix
}
); // 2nd fix
}
} // 3rd fix... and so onhttps://stackoverflow.com/questions/11934876
复制相似问题