如何在单击事件上传递来自两个ID的两个变量


How to pass two variables from two ID on click event

我必须点击ID按钮,每个ID ID从数据库中获取值,通过使用fadeIn和fadeOut显示和隐藏它。当我点击按钮隐藏,我想要它隐藏和显示按钮显示,然后我点击按钮显示它的隐藏和显示按钮隐藏回来。

这是我的HTML代码:
 <tr>
    <td><button value ="HIDE" onclick="morefild(this);" id="show-more<?php echo $row_com_info['com_tin'];?>" /><button value ="SHOW" id ="hid-detail<?php echo $row_com_info['com_tin'];?>" style="display:none" onclick="hidefild(this);" />
    </td>
 </tr>
这是我的JS:
  function morefild(item){
      var ids = $(item).attr("id");
      $('#'+ids).fadeOut();
      $('#hid-detail100077188').fadeIn();
  }
  function hidefild(idhid){
      var idhid = $(idhid).attr("id");
      $('#'+idhid).fadeOut();
      $('#show-more100077188').fadeIn();
 }

*注意:我的代码可以运行静态值我传递给它,但我希望它每一行工作。

请帮助我纠正它,任何命令,如果你不明白我的意思,谢谢!!

据我所知,看起来您有相同格式的多行,并且您希望在单击按钮时隐藏按钮并显示同级按钮。

为了修复你的代码,你可以做下面的事情,这里我们隐藏了被点击的按钮,然后显示下一个/上一个按钮基于哪个被点击

function morefild(item) {
    //hide item and show the next button
    $(item).fadeOut().next().fadeIn();
}
function hidefild(idhid) {
    //hide idhid and show previous button
    $(idhid).fadeOut().prev().fadeIn();
}
一个更jquery化的解决方案是不使用内联事件处理程序…也不是有两个按钮,你可以根据需要的状态更新一个按钮…

演示:小提琴