首页 > 编程技术 > js

jquery判断input值不为空的方法

发布时间:2016-6-12 10:00

<input type="text" class="searchbox" />

<script type='text/javascript'>
$(document).ready(function(){
 //enter回车键激活搜索
  $('.searchbox').bind('keypress', function(event) {
    if (event.keyCode == "13")
    {
      search_news();
    }
  });
var k = $(".searchbox").val();
  if(k!=''){
  document.location = "/plus/search.php?kwtype=0&searchtype=title&q=" + encodeURI(k);
  }
</script>

再给大家分享一个更简洁的方法

$(function() {
      $(".searchbox").blur(function() {
        if ($(".searchbox").val() == "")
        { $(".searchbox").focus(); }
        else
          alert($(".searchbox").val());
      });
    });

标签:[!--infotagslink--]

您可能感兴趣的文章: