0

我目前有一个产品搜索框;您可以通过墨盒名称或打印机名称进行搜索。这些是不同的 SQL 查询,所以我为查询制作了适当的 PHP 文件,但是我无法让 Jquery 检查单选按钮的值,然后根据该单选按钮修改发布文件。

当用户对表单进行任何操作时,它需要检查单选按钮更新。

任何帮助将不胜感激!

这是jQuery:

            $("#faq_search_input").watermark("Begin Typing to Search");
        $("#faq_search_input").keyup(function()
        {
            var faq_search_input = $(this).val();
            var dataString = 'keyword='+ faq_search_input;
            if(faq_search_input.length>1)
            {
                var search_method = $("#search_method").val();
                if(search_method == 'Cartridge'){
                    $.ajax({
                        type: "GET",
                        url: "<?php echo $site_Config_Url; ?>/resources/ajax-search.php",
                        data: dataString,
                        beforeSend:  function() {
                            $('input#faq_search_input').addClass('loading');
                        },
                        success: function(server_response){
                            $('#searchresultdata').html(server_response).show();
                            $('span#faq_category_title').html(faq_search_input);

                            if ($('input#faq_search_input').hasClass("loading")) {
                                $("input#faq_search_input").removeClass("loading");
                            }
                        }
                    });
                }else{
                    $.ajax({
                        type: "GET",
                        url: "<?php echo $site_Config_Url; ?>/resources/ajax-search2.php",
                        data: dataString,
                        beforeSend:  function() {
                            $('input#faq_search_input').addClass('loading');
                        },
                        success: function(server_response){
                            $('#searchresultdata').html(server_response).show();
                            $('span#faq_category_title').html(faq_search_input);

                            if ($('input#faq_search_input').hasClass("loading")) {
                                $("input#faq_search_input").removeClass("loading");
                            }
                        }
                    });
                }
            }return false;
        });
    });

这是表单的 HTML:

 <form action="<?php echo $site_Config_Url; ?>controllers/product_Search_Process.Controllers.php" method="get">
<div style="width:885px;padding-left:15px;height:127px;padding-top:50px;margin-left:auto;margin-right:auto;background-image:url(<?php echo $site_Config_Url; ?>/display/img/layout/ink_and_toner_finder.png);">
    <div style="width:400px;height:108px;float:left;padding-top:7px;">
        <div style="width:400px;padding-left:20px;float:left;">
            <div style="float:left;">
                <select name="drop_1" id="drop_1" style="width:300px;">
                    <option value="" selected="selected" disabled="disabled">Select Printer Brand</option>
                    <?php getTierOne(); ?>
                </select>
            </div>
            <div style="width:80px;padding-left:5px;padding-top:5px;float:left;">
                <span id="wait_1">
                    <img alt="Please Wait" src="<?php echo $site_Config_Url; ?>display/img/ui/ajax-loader.gif"/>
                </span>
            </div>
            <div class="clear"></div>
        </div>
        <div class="clear"></div>

        <span id="result_1" style="display: none;"></span>
        <span id="result_2" style="display: none;"></span>

    </div>
    <div style="width:70px;height:115px;float:left;"></div>
    <div style="width:400px;float:left;">
        <h2 style="padding-top:15px;padding-bottom:0;margin-bottom:0;padding-left:10px;">Search by Cartridge or Printer</h2>
        <div class="clear"></div>
        <div style="padding-left:10px;padding-top:10px;">
            <span style="padding-left:10px;"><input type="radio" name="search_method" value="Cartridge" checked>Cartridge</span>
            <span style="padding-left:20px;"><input type="radio" name="search_method" value="Printer">Printer</span>
            <div class="clear"></div>
            <div style="padding-top:5px;">
                <div style="padding-top:5px;float:left;">
                    <input type="text" name="search_text" style="float:left;width:230px;" id="faq_search_input"/>
                </div>
                <div style="padding-left:18px;float:left;">
                    <input id="submit_right" type="submit" name="submit_right" value="Find Ink!" />
                </div>
                <div class="clear"></div>
            </div>
        </div>
        <div id="searchresultdata" class="faq-articles"> </div>
    </div>
</div>

4

1 回答 1

1

要获取所选单选框的值,您可以使用$('input:radio[name="search_method"]:checked').val();

$("#faq_search_input").watermark("Begin Typing to Search");
$("#faq_search_input").keyup(function() {
    updateResult();
    return false;
});

$('input[name="search_method"]').on('click', updateResult)

function updateResult(){
    var faq_search_input = $('#faq_search_input').val();
    var dataString = 'keyword='+ faq_search_input;
    if(faq_search_input.length>1)
    {
        var search_method = $('input:radio[name="search_method"]:checked').val();

        $.ajax({
            type: "GET",
            url: "<?php echo $site_Config_Url; ?>/resources/ajax-search" + (search_method == 'Cartridge'? '': '2') + ".php",
            data: dataString,
            beforeSend:  function() {
                $('input#faq_search_input').addClass('loading');
            },
            success: function(server_response){
                $('#searchresultdata').html(server_response).show();
                $('span#faq_category_title').html(faq_search_input);

                if ($('input#faq_search_input').hasClass("loading")) {
                    $("input#faq_search_input").removeClass("loading");
                }
            }
        });
    }
}
于 2013-03-01T15:54:34.393 回答