在javascript电台点击输入文本字段

时间:2016-10-13 12:41:04

标签: javascript php jquery

我有三个单选按钮

$auth = "*************************";// Auth Keys
$id="****************";// Record Id

////////////get data by Id from Zoho Lead Module ///////////
$get_url = "https://crm.zoho.com/crm/private/json/Leads/getRecordById?";
$get_query = "authtoken=".$auth."&scope=crmapi&id=".$id."";

$get_curl = curl_init();
curl_setopt($get_curl, CURLOPT_URL, $get_url);
curl_setopt($get_curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($get_curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($get_curl, CURLOPT_TIMEOUT, 60);
curl_setopt($get_curl, CURLOPT_POST, 1);
curl_setopt($get_curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($get_curl, CURLOPT_POSTFIELDS, $get_query);
$get_response = curl_exec($get_curl);
$jfo = json_decode($get_response);
echo "<pre>";
curl_close($get_curl);
print_r($jfo);

选择我需要更改文本字段并在不同选择上获取不同的文本字段。

这是我的功能

   <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 

问题,在前两个单选按钮上,它工作正常,但在第三次单击时我需要简单的文本字段,但它无法正常工作。这是此系统上的现有脚本。 如果我错过任何事情,请告诉我。

1 个答案:

答案 0 :(得分:0)

  

您需要从第三个控件中删除onclick事件   通过jQuery函数(onclick =&#34; document.getElementById(&#39;其他&#39;)。style.display = null;&#34;):

&#13;
&#13;
$('.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');
  }
});
&#13;
<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
&#13;
&#13;
&#13;