2017-09-13 53 views
0

让我们想象一下,我有三个输入不隐藏下拉:当焦点改变

<input type="text" id="a"> 
<input type="text" id="b"> 
<input type="text" id="c"> 

和一个div表写一些数据input "a"input "b"时应该降下来了。 那么我想采取的逻辑是:{ 如果你点击并添加一些数据到input a显示我的表 - >表出现 - >如果我点击input b不要隐藏那div,但是如果我点击其他地方例如input c,隐藏表格。 已经是第三天,我不能这样做。 P.S.我的老板告诉不要使用$超时。应该使用模糊和焦点

+1

请提供完整的代码 –

+0

代码是可以理解的只有我,我只是想知道如何执行此操作。 –

+0

先自己试试 – SilverSurfer

回答

1

只需在同一类中包装输入ab,然后在该类上使用blurfocus

$(document).ready(function(){ 
 
$('#showab').hide(); 
 
$("input.change").focus(function(){ 
 
    $('#showab').show(); 
 
}); 
 
$("input.change").blur(function(){ 
 
    $('#showab').hide(); 
 
}); 
 
});
input{ 
 
display:block; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<input class="change" type="text" id="a"> 
 
<input class="change" type="text" id="b"> 
 
<input type="text" id="c"> 
 
<div id="showab">table here</div>

+0

谢谢@ ab29007我会尝试在我的代码中实现逻辑,并在几分钟内分享答案 –

0

$("#showData").hide(); 
 

 
function lookup(arg) { 
 
    var id = arg.getAttribute('id'); 
 
    var value = this.value; 
 
    console.log(id); 
 
    if (id === "a" || id === "b") { 
 
     $("#showData").show(); 
 

 
    } else { 
 
     $("#showData").hide(); 
 
    } 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<input type="text" id="a" onkeyup="lookup(this);" onClick="lookup(this);"> 
 
<input type="text" id="b" onkeyup="lookup(this);" onClick="lookup(this);"> 
 
<input type="text" id="c" onkeyup="lookup(this);" onClick="lookup(this);"> 
 
<div id="showData">A Or B is Clicked here</div>

0

你要隐藏或显示包含表的DIV时利用的类。

还注意到Jquery的focus的(点击进入),并blur(点击出)班

$(".show").focus(function() 
 
{ 
 
    $('#showTable').show(); 
 
}); 
 
    
 
$(".show").blur(function() 
 
{ 
 
    $('#showTable').hide(); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<input class="show" type="text" id="a"> 
 
<input class="show" type="text" id="b"> 
 
<input class="dontShow" type="text" id="c"> 
 
<div id="showTable" hidden="hidden"> 
 
    <table> 
 
    <thead> 
 
     <tr><th>test 1</th><th>test 2</th></tr> 
 
    </thead> 
 
    <tbody> 
 
     <tr><td>1</td><td>2</td></tr> 
 
     <tr><td>3</td><td>4</td></tr> 
 
    </tbody> 
 
    </table> 
 
</div>