javascript - jquery 索引值的问题
本文介绍了javascript - jquery 索引值的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
有两个input 两个p,如何点击input对应的p显示出来,js的话我懂写,刚接触jquery,请指教一下
<form>
账号: <input type="text"/>
<p>支持中文、字母、数字,4-20个字符</P>
密码: <input type="password"/>
<p>4-20个字符</P>
</form>
解决方案
// 给input提示加了一下className
<form>
账号:
<input class="input-content" type="text" />
<p class="input-tips">支持中文、字母、数字,4-20个字符</P>
密码:
<input class="input-content" type="password" />
<p class="input-tips">4-20个字符</P>
</form>
$('.input-content').on({
focus: function() {
$(this).next('.input-tips:first').show();
},
blur: function() {
$(this).next('.input-tips:first').hide();
}
});
// 题主希望的通过索引实现
$('.input-content').each(function(i, v) {
$(v).on({
focus: function() {
$('form p').eq(i).show();
},
blur: function() {
$('form p').eq(i).hide();
}
});
});
这篇关于javascript - jquery 索引值的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文