jquery发布问题

时间:2011-03-04 14:27:04

标签: php jquery

我有一个代码,我将表格中的值发送到查询所在的php页面,并且发送值我使用$ .post的jquery一切都很顺利。我正在生成一个表和一个按钮现在我希望该按钮将工作,并且表列中的一个具有单选按钮列表,所以我希望该按钮将点击该特定行的无线电ID,但我的按钮不起作用所以请指导我如何做到这一点我的代码就在这里

my javascript function

function searchDetail(searchName) {
    var textName = searchName + "Text";
    var inputText = $('#' + textName).val();
    var formName = searchName + "Form";
    if (inputText === "") {
        $('#' + textName).css("border", "2px solid red").fadeIn(4000);
    }
    else {

        $('#' + textName).css("border", "1px solid #8dd7f6").show(2000);
        $('#searchBox').fadeIn(1000);
        $.post('../search/delete' + searchName + '.php', $('#' + formName).serialize(), function(result) {
            $('#searchBox').html(result);
        })
    }
}

我的PHP代码

if ($count == "0") {
    echo "There is no data with $search = ".$searchKeyword;
} else {
    $color = 2;
    echo "<table cellspacing='0px' cellpadding='7px'><thead><tr><th>#</th><th>book Id</th><th>book Name</th><th>book Writer</th><th>book Price</th><th>Availability</th></tr></thead><tbody>";
    while ($row = mysqli_fetch_array($result)) {
        $checkBook = $row['booktotal'] - $row['bookremain'];
        if ($checkBook == 1) {
            $status = "Yes";
        } else {
            $status = "No";

        }

        if ($color % 2 == 0) {
            echo "<tr class='even'><td><input type=radio name=group1 value=".$row['bookId']."></td><td>".$row['bookId']."</td><td>".$row['bookName']."</td><td>".$row['bookWriter']."</td><td>".$row['bookPrice']."</td><td>".$status."</td></tr>";
            $color = $color + 1;
        } else {
            echo "<tr class='odd'><td><input type=radio name=group1 value=".$row['bookId']."></td><td>".$row['bookId']."</td><td>".$row['bookName']."</td><td>".$row['bookWriter']."</td><td>".$row['bookPrice']."</td><td>".$status."</td></tr>";
            $color = 2;
        }

    }
    echo "</tbody></table><br><input type=button value=Delete id=deleteButton onclick='check()'> <script type=text/javascript> function check(){alert(Hello);}</script>";

    mysqli_close($con);
}


?>

我的HTML代码

<body>
    <div id="deleteFormTable">
        <span id="headerFont">Enter Information to Delete Book</span><br><br>
        <form id="bookSearchForm" name="bookSearchForm"><label>Search Book:</label>&nbsp;&nbsp;&nbsp;<input type="text" id="bookSearchText" name="bookSearchText"/>&nbsp<select id="bookSearchOption" name="bookSearchOption"><option id="bookSearchId">Id</option><option id="studentSearchName">Name</option></select>&nbsp;&nbsp;&nbsp;<input type="button" value="Search" id="bookSearch" name="bookSearch" onclick="searchDetail(this.id)"></form>
    </div>
    <div id="searchBox">
        <center><div id="searchLoadBox"><img src="../images/loadings.gif" alt="..."></div></center>
    </div>
</body>

1 个答案:

答案 0 :(得分:0)

好的,我想我知道你在问什么。

您有一个项目列表,旁边有单选框,一旦用户单击一个然后单击该按钮,您希望将“值”绑定到该单选按钮。

如果是这种情况,您可以使用它来查找“已检查”无线电组的值。

$("#deleteButton").click(function()
{
    var bookId = $("input[@name='group1']:checked").val();
}