【问题标题】:Onclick on a radiobutton list using javascript使用javascript单击单选按钮列表
【发布时间】:2020-11-05 10:26:34
【问题描述】:

嘿嘿,

我想使用 get 将 javascript 中单选按钮的值传输到新页面。但是当我单击单选按钮时没有任何反应。

很遗憾,我不知道该怎么做,希望您知道。

感谢您的帮助!

这是脚本:

<script>
$(document).ready(function(){
 
 load_data();

 function load_data(query)
 {
  $.ajax({
   url:"fetch.php",
   method:"POST",
   data:{query:query},
   dataType:"json",
   success:function(data)
   {
    $('#total_records').text(data.length);
    var html = '';
    if(data.length > 0)
    {
     for(var count = 0; count < data.length; count++)
     {
      html += '<tr>';
      html += '<td> <input type="radio" name="auswahl" onclick="window.location.href = "kunden_bearbeiten.php?var=value" value="+data[count].id+"> </td>';
      html += '<td>'+data[count].id+'</td>';
      html += '<td>'+data[count].firma+'</td>';
      html += '<td>'+data[count].vorname+'</td>';
      html += '<td>'+data[count].nachname+'</td>';
      html += '<td>'+data[count].strasse+'</td>';
      html += '<td>'+data[count].plz+'</td>';
      html += '<td>'+data[count].ort+'</td></tr>';
     }
    }
    else
    {
     html = '<tr><td colspan="5">Kein Eintrag gefunden</td></tr>';
    }
    $('tbody').html(html);
   }
  })
 }

 $('#search').click(function(){
  var query = $('#tags').val();
  load_data(query);
 });

});
</script>

【问题讨论】:

    标签: javascript php mysql ajax get


    【解决方案1】:

    这是因为你听点击事件我主要使用 onchange 事件。这对你有用。

    <input type="radio" value="me" onchange="window.location='shop.php?value=' + this.value">
    

    【讨论】:

    • 添加它的 onchange =' window.location.href = "kunden_bearbeiten.php?var="+ this.value' not var=value
    • 感谢您的快速回复。不幸的是,它还没有解决我的问题。我换了他们的线并调整了它,但这也不起作用。如果我现在选择单选按钮并单击另一个单选按钮,则两者都保持选中状态。
    • 我添加了这个:html += ' ';
    【解决方案2】:

    我找到了一个适合我的解决方案。我将类型从广播更改为提交。

    <form method="get"><input class="ButtonSelect" type="submit" name="auswahl" formaction="kunden_bearbeiten.php?var=value" value="'+data[count].id+'"></form>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-16
      • 1970-01-01
      • 2014-03-03
      相关资源
      最近更新 更多