关于form表单 单选框 input type=radio 选中提交的问题

<script type="text/javascript">//第一个$(document).ready(function(){$("#search_results").slideUp(); $("#search_button").click(function(e){if($("#search_term").val()==""){ }else{ e.preventDefault(); ajax_search();} })});function ajax_search(){ $("#search_results").show(); var search_val=$("#search_term").val(); $.post("./find.php", {search_term : search_val}, function(data){ if (data.length>0){ $("#search_results").html(data); } }) } //第一个结束。//第二个function bottomForm(){ var a =document.searchform.search_term.value; window.open("http://www-31.com/support/techdocs/cn/surfcategory/queryByBarCode/s?barcode=" + a); return false; } //第二个结束 </script></head><body><div id="input"> <form id="searchform" method="post" > <input type="text" name="search_term" id="search_term" placeholder="请输入内容" required oninvalid="setCustomValidity('请输入您要查询的内容')" oninput="setCustomValidity('')"> <input type="submit" value="search" id="search_button"><div id="dxk"> <input type="radio" name="check" value="site" id="searchSite" checked> <label for="searchSite" id="siteNameLabel">Search</label> //当选中这个单选按钮,输入内容,点submit按钮执行上边第一个js <input type="radio" name="check" value="web" id="searchWeb"> <label for="searchWeb">Search The Web</label> //当选中这个单选按钮,输入内容,点submit按钮执行上边第二个js</div> </form></div></body>
选择单选按钮,执行对应的js

$(document).ready(function(){
$("#search_button").click(function(){
var a =$(":radio[name="check"]:checked").val(); //获取选中的值
if(a == "site"){
ajax_search(); //调用第一个函数
}else{

bottomForm(); //调用第二个函数
}

});
});追问

您好,您给的这段代码我应该怎么跟我第一条js结合在一起,我上边有ready和click方法了,我把我第一条ready整个部分://第一个
$(document).ready(function(){
$("#search_results").slideUp();
$("#search_button").click(function(e){
if($("#search_term").val()==""){
}
else{
e.preventDefault();
ajax_search();
}
})
});
​替换成您的之后不输出结果了。

追答$(document).ready(function(){
    $("#search_results").slideUp(); 
    $("#search_button").click(function(e){
        var a =$(":radio[name="check"]:checked").val();    //获取选中的值
        if(a == "site"){
             if($("#search_term").val()==""){
             }else{
                e.preventDefault(); 
                ajax_search();    //调用第一个函数
             } 
          }else{
                bottomForm();    //调用第二个函数
          }
       });
        
   
});

function ajax_search(){ 
    $("#search_results").show(); 
    var search_val=$("#search_term").val(); 
    $.post("./find.php", {search_term : search_val}, function(data){
        if (data.length>0){ 
            $("#search_results").html(data);
    
        } 
    }); 
}

function bottomForm(){
var a =document.searchform.search_term.value;
window.open("http://www-31.com/support/techdocs/cn/surfcategory/queryByBarCode/s?barcode="+ a);
return false; 
}

追问

我明早测试下这个,告诉您结果,辛苦您了,谢谢您

大师,还是不行,不返回结果,slideUp也失效了

追答

var a =$(":radio[name='check']:checked").val(); //获取选中的值
这句改一下,不好意思,符号用错了

温馨提示:答案为网友推荐,仅供参考
相似回答
大家正在搜