gpt4 book ai didi

php - jQuery 对话框在更改时不显示 div

转载 作者:行者123 更新时间:2023-11-30 13:31:09 25 4
gpt4 key购买 nike

我正在使用对话框显示表单并在提交时回显消息。这很好用。我还有一个下拉菜单,从中选择填充第二个下拉菜单的值。这本身效果很好,但如果我尝试合并两者,则不会显示或填充更改中的 div id="divId"。现在我将第一个承认我的 jQuery 知识至少可以说是基本的,所以我将感谢专家的任何帮助。我已经包含了代码以供您注意并等待您的评论。谢谢

此代码在单独的 function.js 中

// Function to add box

function addbox() {

$("#boxaddform").dialog({
autoOpen: false,
resizable: true,
modal: true,
title: 'Submit a box intake request',
width: 470,
beforeclose: function (event, ui) {
$("#addbox").html("");

}

});

$('#boxsubmit').click(function () {

var box = $('.box').val();
var service = $('#service').val();
var authorised = $('.authorised').val();
var data = 'box=' + box + '&authorised=' + authorised + '&service=' + service;
$.ajax({
type: "POST",
url: "boxesadd.php",
data: data,
success: function (data) {
$("#boxform").get(0).reset();
$('#addbox').html(data);
//$("#form").dialog('close');
$("#flex1").flexReload();

}
});
return false;

});

$("#boxaddform").dialog('open');

}

html

<script language="javascript" type="text/javascript">
$(function() {
$("#company").change(function() {
if ($(this).val()!="") $.get("getOptions.php?customer=" + $(this).val(), function(data) {
$("#divId").html(data);
});
});
});
</script>

<!--- Form to add box -->

<div id="boxaddform" style="display:none;">
<form id="boxform" method="post" class="webform" name="boxform" />

<label for="company">Select a Company:</label>
<select name="company" id="company" />
<option SELECTED VALUE="">Select a Company</option>
<?php
do {
?>
<option value="<?php echo $row_Recordsetcust['customer']?>"><?php echo $row_Recordsetcust['customer']?></option>
<?php

}
while ($row_Recordsetcust = mysql_fetch_assoc($Recordsetcust));
$rows = mysql_num_rows($Recordsetcust);
if($rows > 0)

{
mysql_data_seek($Recordsetcust, 0);
$row_Recordsetcust = mysql_fetch_assoc($Recordsetcust);
}

?>
</select><br />
<div id="divId"></div><br />
<label for="service">Enter service level:</label>
<select name="service" id="service">
<option SELECTED VALUE="">Select an option</option>
<option value="Standard">Standard</option>
<option value="Rapid">Rapid</option>
</select>
<br />
<label for="box">Enter a Box#:</label>
<input id="box" name="box" type="text" class="text ui-widget-content ui-corner-all inputbox box" />

<label for="authorised">Requested By:</label>
<input name="authorised" type="text" class="text ui-widget-content ui-corner-all inputbox authorised" id="authorised" value="<?php echo $_SESSION['kt_name_usr']; ?>" /><br />
<div id="addbox"></div>
<button id="boxsubmit" class="submit">Submit</button>
</form>
</div>

获取选项.php

<?php
$customer = mysql_real_escape_string( $_GET["customer"] ); // not used here, it's the customer choosen

$con = mysql_connect("localhost","root","");
$db = "sample";
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db($db, $con);
$query_rs_select_address2 = sprintf("SELECT * FROM company_com where idcode_com = '$customer'");
$rs_select_address2 = mysql_query($query_rs_select_address2, $con) or die(mysql_error());
$row_rs_select_address2 = mysql_fetch_assoc($rs_select_address2);
$totalRows_rs_select_address2 = mysql_num_rows($rs_select_address2);



echo 'Select delivery address'.'<select name="customeraddress">';
echo '<option value="">Select delivery address</option>';
while ($row_rs_select_address2 = mysql_fetch_assoc($rs_select_address2))
{
$address=$row_rs_select_address2['address1_com']. " ".
$row_rs_select_address2['address2_com']. " ".
$row_rs_select_address2['address3_com']. " ".
$row_rs_select_address2['town_com']. " ".
$row_rs_select_address2['postcode_com'];
echo '<option
value="address">'.$address.'</option>';
}
echo '</select>';
?>

最佳答案

试试把这个

$("#company").live('change', function() {
if ($(this).val()!="") $.get("getOptions.php?customer=" + $(this).val(), function(data) {
$("#divId").html(data);
});
});

在您提供的脚本的第一部分。

我的想法是,也许更改处理代码没有捕获下拉列表并且根本没有运行。为了测试 alert('test');在你当前的 $("#company").change(function(){...}); block 。

关于php - jQuery 对话框在更改时不显示 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6735532/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com