首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >多个事件的Jquery绑定

多个事件的Jquery绑定
EN

Stack Overflow用户
提问于 2018-10-16 02:54:30
回答 1查看 22关注 0票数 0

我是jquery的业余爱好者。我正在尝试创建一个搜索函数,它可以很好地使用,直到select元素没有包含在内。你能检查一下我的错误在哪里吗?

代码语言:javascript
运行
复制
$(function () {
$('#keresomezo').bind('keyup change',(function () {

var that = this,
value = $(this).val();

// Take values from html
keresomezo = $("input[name=keresomezo]").val();
keresomezo_ = $("input[name=keresomezo_]").val();
keresomezo_zip = $("input[name=keresomezo_zip]").val();
keresomezo_city = $("input[name=keresomezo_city]").val();
keresomezo_rank = $( ".rank option:selected" ).val();
//keresomezo_rank = $("input[name=keresomezo_rank]").val();

// minimum length
if (value.length >= minlength ) {
// loading
    $('#ccenter').append('<div id="loadingmessage"><img src="style/images/ajax-loader.gif"></div>');

    $.ajax({
    type: "GET",
    url: "pages/search.php",
    data: {
        'company' : keresomezo,
        'contact' : keresomezo_,
        'zip' : keresomezo_zip,
        'city' : keresomezo_city,
        'rank' : keresomezo_rank
        },
        dataType: "text",
        success: function(msg){
        //we need to check if the value is the same
        if (value==$(that).val()) {
            // Set navbox info
                loadnavbox("Company search");
            //Receiving the result of search here
                document.getElementById("ccenter").innerHTML=msg;
                }
            }
        });
    }
}));
});

和html:

代码语言:javascript
运行
复制
    <div class="contact_keresomezo" id="contact_keresomezo">
  <input type="text" name="keresomezo" id="keresomezo" title="Search by company name" placeholder="Company name">
  <input type="text" name="keresomezo_" id="keresomezo" title="Search by contact name" placeholder="Contact name">
  <input type="text" name="keresomezo_zip" id="keresomezo" title="Search by ZIP code" placeholder="ZIP">
  <input type="text" name="keresomezo_city" id="keresomezo" title="Search by City" placeholder="City">
  <select name="keresomezo_rank" id="keresomezo" class="rank" title="Search by Rank">
  <option value="" selected>Rank</option>
    <?php print company_rank("",$mysqli); ?>
  </select>

</div>

因此,代码在没有select元素的情况下可以工作,但是有了它,它就不能工作了。我已经用了两天了,这让我很抓狂。

谢谢!

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52823098

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档