doulin6761 2016-06-28 20:43
浏览 73
已采纳

如何根据按下的按钮来调用函数来显示div?

I'm trying to generate a set of N buttons, one for each row of a DB table, I need to show a <div> by putting his style="display:none" to style="display:block" when one of the buttons is clicked, this <div> will show a form.

Until now i got this:

home.PHP

    <div id="add" style="display:none;">
        <form action="#" method="post" id="form">
            <div src="close" id="close" onClick="div_hide()">X</div>
            Aggiungi
            <input type="text" name="soldi" id="campo" placeholder="Soldi">
            <a id="submit" href="">
                <button>Aggiungi</button>
            </a>
        </form>
    </div>
<?php
    while($sezioni = mysqli_fetch_assoc($sezione_sql)){     
        echo "<div class =\"sezione\">
                  <a id=\"popup\" onclick=\"div_show()\">
                      <div class=\"pulsante\">add</div>
                  </a>
              </div>";
    }
?>

java.JS

function div_show() {
    document.getElementById('add').style.display = "block";
}

function div_hide(){
    document.getElementById('add').style.display = "none";
}

How could I call a function on submit that will update a determinated DB row getting in input an ID of the pressed button?

  • 写回答

1条回答 默认 最新

  • drq61040 2016-06-28 21:02
    关注
    1. Pass db_id through javascript function.
    2. In javascript function assign the passed db_id to the hidden input field in the form.

    Passing db_id:

    while($sezioni = mysqli_fetch_assoc($sezione_sql)){  
        $db_id = $sezioni['id']; // id from database   
            echo "<div class =\"sezione\">
                      <a id=\"popup\" onclick=\"div_show($db_id )\">
                          <div class=\"pulsante\">add</div>
                      </a>
                  </div>";
        }
    

    In Form add a hidden input field

    <input type="hidden" name="db_id" id="db_id" value="">
    

    In Javascript function

    function div_show(db_id) {
        document.getElementById('add').style.display = "block";
        document.getElementById('db_id').value = db_id;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思