在html页面内加载php脚本

时间:2013-06-23 14:09:30

标签: php javascript jquery

我想在select on change事件上加载页面。但它不显示页面。页面上的内容只是:这是银行/这是现金。

<!DOCTYPE html>
<html>
<select id = "ddl" onchange="changeSheet()">
<option value = "bank">Bank Statement</option>
<option value = "cash">Cash Book</option>
</select>

<div id = "sheet">
</div>

<script>
function changeSheet()
{
    document.getElementById('sheet').innerHTML = "";
    var e = document.getElementById("ddl");
    var strUser = e.options[e.selectedIndex].value;

    if(strUser == 'bank')
    {
        $("#sheet").load("bank.php");
    }
    else 
    {
        $("#sheet").load("cash.php");
    }
}
</script>

1 个答案:

答案 0 :(得分:0)

使用JQuery这是正确的方法: DEMO

<!DOCTYPE html>
<html>
<select id = "ddl" onchange="changeSheet()">
    <option value = "bank">Bank Statement</option>
    <option value = "cash">Cash Book</option>
</select>

<div id = "sheet"></div>

<script>
$(document).ready(function(){
    $("#ddl").change(function(){
        if($(this).val() === "bank")
            $("#sheet").load("bank.php");    
        else 
            $("#sheet").load("cash.php");   
    });
});
</script>