下記のようなコードで、.main_textareaにfocusされている時、radioボタンの値を取得し
Aであれば.main_textareaが.focus中にborder-colorがred
Bであれば.main_textareaが.focus中にborder-colorがblue
を実装したいと考えております。
下記のようなコードを書いてもfocusのタイミングによって処理するため、意図した処理が実装できません。
イメージとしては.main_textareaがfocusされたら、同時にradioボタンの値を取得して、
それに応じてborder-colorが振り分けられるものを想定しております。
jqueryでcssを指定する際に、
if (get_val=="cof") {
$(this).css(':focus','border-color','#ff0000');
})
}
のように記載できないため、方法を探しております。
よろしくお願い申し上げます。
html
1<label> 2 <input type="radio" name="radio" checked value="A"/> 3 <div class="front-end boxs"> 4 <span>A</span> 5 </div> 6</label> 7 8<label> 9 <input type="radio" name="radio" value="B"/> 10 <div class="back-end boxs"> 11 <span><B</span> 12 </div> 13</label> 14 15<label>Text</label> 16<textarea class="main_textarea" rows="3"></textarea>
Jquery
1$(function(){ 2 $('.main_textarea').on('focus',function(){ 3 let get_val=$('input[name=radio]:checked').val(); 4 if (get_val=="A") { 5 $(this).focus(function(){ 6 $(this).css('border-color','red'); 7 }) 8 } 9 if (get_val=="B") { 10 $(this).focus(function(){ 11 $(this).css('border-color','blue'); 12 }) 13 } 14 }) 15})
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/07/29 12:51
2018/07/29 13:21
2018/07/29 14:36