[英]input text field on javascript radio click
I have three radio buttons 我有三个单选按钮
<input type="radio" name="selection" class="selection" data-id='0' value="search" checked="checked" />Search for a client
<input type="radio" name="selection" class="selection" data-id='0' value="sel" />Mass E-mail
<input type="radio" name="selection" class="selection" data-id='0' value="others" onclick="getElementById('other').style.display = null;" />Other E-mail
on select I need to change the text fields and get different text fields on different selects. 在选择上,我需要更改文本字段并在不同的选择上获得不同的文本字段。
Here is my function 这是我的功能
$('.selection').live('click',function(){
var id = $(this).attr('data-id');
if(id == 0){id='';}
var selectedVal = $(this).val();
if(selectedVal=='sel'){
$('#customer_search_query'+id).attr('style','display:none');
$('#customers_email_address'+id).attr('style','display:inline');
$('#customer_id'+id).val('');
$('#customer_search_query'+id).val('');
$('#customers_email_address'+id).val('');
$('#other'+id).attr('style','display:none');
}else if(selectedVal=='search'){
$('#customer_search_query'+id).attr('style','display:inline');
$('#customers_email_address'+id).attr('style','display:none');
$('#customer_id'+id).val('');
$('#customer_search_query'+id).val('');
$('#customers_email_address'+id).val('');
$('#other'+id).attr('style','display:none');
}
else {
$('#customer_search_query'+id).attr('style','display:none');
$('#customers_email_address'+id).attr('style','display:none');
$('#other'+id).attr('style','display:inline');
}
});
The problem, on first two radio buttons, it is working perfectly but on third click I need simple text field and it is not working. 问题是,在前两个单选按钮上,它运行正常,但是在第三次单击时,我需要简单的文本字段,但它不起作用。 This is existing script on this system. 这是该系统上的现有脚本。 Please let me know if I missed any thing. 如果我错过任何事情,请告诉我。
You need to remove the onclick event from the third control to go through the jQuery function (onclick="document.getElementById('other').style.display = null;"): 您需要从第三个控件中删除onclick事件以通过jQuery函数(onclick =“ document.getElementById('other')。style.display = null;”):
$('.selection').live('click', function() { var id = $(this).attr('data-id'); if (id == 0) { id = ''; } var selectedVal = $(this).val(); if (selectedVal == 'sel') { $('#customer_search_query' + id).attr('style', 'display:none'); $('#customers_email_address' + id).attr('style', 'display:inline'); $('#customer_id' + id).val(''); $('#customer_search_query' + id).val(''); $('#customers_email_address' + id).val(''); $('#other' + id).attr('style', 'display:none'); } else if (selectedVal == 'search') { $('#customer_search_query' + id).attr('style', 'display:inline'); $('#customers_email_address' + id).attr('style', 'display:none'); $('#customer_id' + id).val(''); $('#customer_search_query' + id).val(''); $('#customers_email_address' + id).val(''); $('#other' + id).attr('style', 'display:none'); } else { $('#customer_search_query' + id).attr('style', 'display:none'); $('#customers_email_address' + id).attr('style', 'display:none'); $('#other' + id).attr('style', 'display:inline'); } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script> <input type="radio" name="selection" class="selection" data-id='0' value="search" checked="checked" />Search for a client <input type="radio" name="selection" class="selection" data-id='0' value="sel" />Mass E-mail <input type="radio" name="selection" class="selection" data-id='0' id="other" value="others" />Other E-mail
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.