单击提交如何显示表格并将表单值传递给 html 和 js 中的后端?

问题描述

我正在开发一个 HTML 页面,该页面接受日期值作为输入,并需要根据日期在表格中显示数据。 在页面加载时,我会显示日期字段和提交按钮。

点击提交按钮,我需要执行2个操作:

1) 应该提交日期值,以便我可以在后端获取这些值并将它们传递给 python API。 2)在包含该python API数据的同一页面显示该表。

我可以单独执行上述操作,但可以同时在一个提交按钮中执行。

$(document).ready(function() {

      var url = "{{url_for('data_api') }}";
      $.getJSON(url,function(data) {
        var thd,tbd = ' ';
        var mydata = data['data'];
        thd += '<thead style="text-align:center"><tr>';
        thd += '<th scope="col" width="15%">CustID</th>';
        thd += '<th scope="col" width="25%">CustName</th>';
        thd += '<th scope="col" width="20%">Date</th>';
        thd += '</tr></thead>

        $.each(mydata,function(key,value) {
          //Will get the data from api and insert those data in the table
        });
      });

      $("#sbtn").click(function() {
            if ($("#my_date_picker").val().length === 0){
                alert('Invalid');
                return false;
              }
              else {
                $("form").submit();
              }
            });
<!DOCTYPE html>
<html>

<head>
  <title>
    Date Picker
  </title>

  <link href='https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/ui-lightness/jquery-ui.css' rel='stylesheet'>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js">
  </script>
  <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js">
  </script>
</head>

<body>
  <form method="POST">
    Date: <input type="text" id="my_date_picker">
    <button id="sbtn">Submit</button>

    <div id="mytable">
      <table id="datatable" style="display:none">

      </table>
    </div>
  </form>
  <script>
    $(document).ready(function() {

      $(function() {
        $("#my_date_picker").datepicker();
      });
    })
  </script>
</body>

</html>

有没有办法用一个提交按钮来执行这两个操作。?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...