2017-07-07 13 views
0

ラジオボタンが2つあり、ラジオボタンがクリックされていないときにラジオボタンをクリックして削除するとテキストボックスに(*)を表示する必要があります。
私の見解:JavaScriptの無効化タグを有効にする方法

<label>code<sup id="star" disabled>*</sup></label>    
     >Add to electronic<input type="radio" name="yes" id="yes"/>onchange="starenable()"/><input type="radio" name="yes" 
     > id="no"/>onchange="starenable()"/>no 

私のjavascript:

function starenable() { 
     if (document.getElementById('yes').checked) { 
      document.getElementById("star").disabled = false; 
     } else if (document.getElementById('no').checked) { 
      document.getElementById("star").disabled = true; 
     } 
    } 

私はこれを試していないが、ビューに変更。何か案は?

答えて

0

入力を入力してdisable属性.Changeにsubを持っている.AND適切format.Then上のHTMLコードを揃える*がチェックラジオボタンに依存追加

を更新注:subタグに無効属性がありません

function starenable() { 
 
    if (document.getElementById('yes').checked) { 
 
    document.getElementById("star").disabled = false; 
 
    } else if (document.getElementById('no').checked) { 
 
    document.getElementById("star").disabled = true; 
 
    } 
 
    document.getElementById("star").innerHTML = document.getElementById('yes').checked ? '*' : ''; 
 
}
<label>code <sub id="star"></sub></label> Add to electronic 
 
<input type="radio" name="yes" id="yes" onchange="starenable()" />yes 
 
<input type="radio" name="yes" id="no" onchange="starenable()"/>no
ここ

+0

ですfテキストボックス – ashwanth

+0

@ashwanth私の更新された答えを参照 – prasanth

+0

なぜ私たちは二重引用符を与えているのですか? – ashwanth

0

私は、*は、Oを表示することを必要とするソリューションがhttps://jsfiddle.net/me9uwL2d/

<input type="radio" name="test" value="Yes" />Yes 
<input type="radio" name="test" value="No" />No 
<input type="text" /> 

$('input[type="radio"]').change(function() { 
    if($(this).is(':checked') && ($(this).attr('value') == 'Yes')) { 
     $('input[type="text"]').val("*"); 
    }else{ 
     $('input[type="text"]').val(''); 
    } 
}); 
0

$(document).ready(function() { 
 
    $('input[type=radio][name=yes]').change(function() { 
 
     if (this.id == 'yes') { 
 
     $('#star').hide(); 
 
     } 
 
     else if (this.id == 'no') { 
 
      $('#star').show(); 
 
     } 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> 
 
<label>code<span id="star" >*</span></label>    
 
     Add to electronic 
 
     <input type="radio" name="yes" id="yes"/>yes 
 
     <input type="radio" name="yes" 
 
     id="no"/>no
使用この

+0

このコードをashwanth – jeevanswamy21

+0

で使用してください。私のプロジェクトではうまくいきませんでしたか? – ashwanth

+0

のエラーが発生しているか、またはjqueryの競合を確認しています – jeevanswamy21

0
<label>code<sup id="star" style="visibility:hidden">*</sup></label> 
Add to electronic 
<input type="radio" name="yes" id="yes" onchange="starenable()"/>yes 
<input type="radio" name="yes" id="no" onchange="starenable()"/>no 

function starenable() { 

    if (document.getElementById('yes').checked) 

     document.getElementById("star").style.visibility = "visible"; 

    else if (document.getElementById('no').checked) 

     document.getElementById("star").style.visibility = "hidden"; 

    } 
関連する問題