【发布时间】:2017-03-20 04:17:29
【问题描述】:
我很想通过跨度自动生成的输入来解决我的问题。我在我的网站上使用 Wordpress 插件 Contact Form 7,我希望在用户使用输入字段时为标签设置动画。
当输入字段处于焦点或在其中键入内容时,活动类应出现在具有“grid-3”类的 div 中。
我尝试自己获取 javascript,但它不起作用:
$('.wpcf7-form-control-wrap').each(function() {
//console.log($(this));
$(this).on('focus', function() {
$(this).parent().parent().addClass('active');
});
$(this).on('blur', function() {
if ($(this).val().length == 0) {
$(this).parent().parent().removeClass('active');
}
});
if ($(this).val() != '') $(this).parent('.grid-3').addClass('active');
});
HTML:
<div class="grid-3">
<label for="schenkel2">Schenkel 2 in mm</label>
<span class="wpcf7-form-control-wrap schenkel2">
<input type="text" name="schenkel2" value="" size="40" class="wpcf7-form-control wpcf7-text" id="schenkel2" aria-invalid="false">
</span>
</div>
【问题讨论】:
-
为什么需要在焦点上添加一个类?是要改变造型吗?如果是这样,
:focus伪类就是为这种场合而设计的
标签: javascript html input addclass contact-form-7