我有一个文本框和下拉列表框。在下拉列表框中,我列出了根据设备具有不同价格的设备列表。用户将设备用于天数的租金。现在我使用 php 函数计算租金价格。
现在我想要的只是,通过使用 php 在 html 表单中调用该函数,在文本框中单击相应的项目时,在文本框中显示该受尊重的计算值。
谁能帮我用这个例子解决这个问题?
还没有测试过它,而且由于您没有提供更多信息,这是基于一个 php 作为源文件,当使用 2 个参数调用时,它回显了价格:
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
$("#items").change(function() {
$.ajax({
url: "http://url/data.php",
data: {
selectedItem: $("#items").val(),
days: $("#days").val()
},
success: function() {
$("#total").html(data)
}
}
}
</script>
</head>
<body>
<form>
<input id="days" value="1" />
<select id="items">
<option value="1">Object 1</option>
<option value="2">Object 2</option>
</select>
Calculated costs: <span id="total"></span>
</form>
</body>