0

在使用 load 语句传递 jquery 变量的文档中,我似乎找不到任何示例。我尝试使用和不使用引号,将整个变量语句放入,但没有运气。调试时其他一切似乎都可以工作,但没有传递变量,请看一下:编辑:我还应该说清楚我尝试了 {term: d} 和 {term: var d} 但都不起作用。

<script>
function callMe() {
    for (var i = 1; i< 2; i++){
        var b = $('#song'+i).val();
        var c = $('#artist'+i).val();
        var d = b +" "+ c; 
        // alert(d);
        //$('#results').load('getWeb.php', {term: d});
        $('#results').load('getWeb.php', {term: 'd'});
    }
    // var b = $('#song1').val();
    // alert(b);
}
$(document).ready(function(){
    callMe();
});
</script>

<form>
Song <input type ="text" name ="song1" id ="song1">
Artist <input type ="text"  name ="artist1" id ="artist1"><br />
<input type ='submit' value ='Submit' onClick="callMe();">
</form>
4

1 回答 1

1

我为你做了一个工作示例。一个起点。

<?php
if (isset($_POST['term'])) {
    echo $_POST['term'];
    exit;
}
?><!DOCTYPE html>
<html>
    <head>
        <title>Info</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
        <script type="text/javascript">
            function callMe() {
                var b = $('#song1').val();
                var c = $('#artist1').val();
                var d = b + ":" + c;
                $('#results').load('', {term: d});
            }
            $(function() {
                $('form').submit(function() {
                    callMe();
                    return false;
                });
            });
        </script>
    </head>
    <body>

        <form action="" method="post">
            Song <input type ="text" name ="song1" id ="song1">
            Artist <input type ="text"  name ="artist1" id ="artist1"><br />
            <input type ='submit' name="info" value ='Submit'>
        </form>
        <div id="results">

        </div>

    </body>
</html>
于 2013-03-15T00:18:08.903 回答