有两个input 两个p,如何点击input对应的p显示出来,js的话我懂写,刚接触jquery,请指教一下
<form>
账号: <input type="text"/>
<p>支持中文、字母、数字,4-20个字符</P>
密码: <input type="password"/>
<p>4-20个字符</P>
</form>
有两个input 两个p,如何点击input对应的p显示出来,js的话我懂写,刚接触jquery,请指教一下
<form>
账号: <input type="text"/>
<p>支持中文、字母、数字,4-20个字符</P>
密码: <input type="password"/>
<p>4-20个字符</P>
</form>
$("input").on("click",functioin(){
var index= $(this).index();
$("p").addClass("hidden");
$("p").eq(index).removeClass("hidden");
})
<form>
账号: <input type="text"/>
<p style="display: none;">支持中文、字母、数字,4-20个字符</P>
密码: <input type="password"/>
<p style="display: none;">4-20个字符</P>
</form>
$(function(){
$('input').on('focus',function(){
$(this).next().show();
}).on('blur',function(){
$(this).next().hide();
})
})
遍历(each)取到input相应的index
jQuery("input").each(function(index,el){
jquery(el).on("click",function(){
jQuery("p").addClass("hidden");
jQuery("p").eq(index).removeClass("hidden");
});
});
10 回答11.1k 阅读
6 回答3k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决