2016-05-18 1 views
1

ラベルの姓では、フォーカスが2番目の選択要素にあるときにラベルが太字に変わりません。私はこのコード選択要素にフォーカスがあるときにラベルを太字に変更する方法 - JQuery

<form id="formul"> 
    <label for="a1">First name:</label><br> 
    <input type="text" name="firstname" id="a1" class="_lblbold"><br> 
    <label for="a2">Last name:</label><br> 
    <input type="text" name="lastname" id="a2" class="_lblbold"> 
    <select id="a2"><option value="">Choose</option></select> 
    <select id="a3"><option value="">Choose</option></select><br> 
    <label className="col-md-5 lbl_e2bnames" For="id_input_addit">Additional</label> 
    <textarea id="id_input_addit" cols="50" rows="7" placeholder="ABCD"></textarea><br> 
</form> 

のjQuery

$('form :input').bind({ 
    focus: function() { 
     var id = $(this).attr('id').toString(); 
     var add = $("label[for='" + this.id + "']").addClass('labelfocus'); 
     $("label[]").addClass('labelfocus'); 


    }, 
    blur: function() { 
     $('label').removeClass('labelfocus'); 
     $("label").removeClass('labelfocus'); 
    } 
}); 

CSSここで

.labelfocus { 
    font-weight:bold; 
} 

を持って

これを行う方法上の任意のヒントは、Codepenます:http://codepen.io/parlop/pen/oxOoba

答えて

2

ベースあなたのロジックにエドの問題は、2番目の要素は、別のIDに

「A2」のためには、概念的には間違った使用は、あなたができる、その場合には、同じIDを持つ2種類以上の元素であることを

<select id="a3"><option value="">Choose</option></select><br> 

変更を使用していることです同じIDを使用する代わりにクラスを使用する

関連する問題