获取从动态表中单击的文本的值并传递给 Servelet

get value of text clicked on from dynamic table and pass to servelet

本文关键字:Servelet 文本 动态 单击 获取      更新时间:2023-09-26

在jsp文件中,我根据用户的发票或购买创建一个动态表。我创建表没有问题。问题是,我引用了该行的第一个字段(发票编号),并希望显示一个表单,其中包含有关该特定发票编号的详细信息。窗体将在同一屏幕上弹出,并带有关闭按钮以返回到列表并单击另一个发票编号。如何根据用户单击的发票编号传递发票编号并填充 href 表单?

这是用于创建表的 html:

    <table class="tableinvoice" >
            <tr>
            <th scope="col" >Invoice number</th>
            <th scope="col">Name</th>
            </tr>
        <tbody>     
        <tr>
            <td> <a href="#form" id='formid'> <%= ls.get(0) %> </a></td>
            <td> <%= ls.get(1) %></td>
        </tr>               
        </tbody>
    </table>

这是同一 jsp 上的 html 形式:

 <div id="form" class="overlay">
  <div class="popup">
    <a class="close" href="#">×</a>
    <div class="content">
       *****invoice information here***
    </div>
</div>

欢迎任何其他建议来实现此目的

将发票编号放在数据属性中

<a class="invoice-link" href="#form" id='formid' data-inv="1223">

然后简单的 ajax 获取数据并打开模态:

$('.invoice-link').click(function(e){
     e.preventDefault();
     var $link = $(this),  
         $form_modal = $( $link.attr('href') ),
         inv = $link.data('inv'),
         api_url = '/path/to/server/' + inv;
     // use `$.ajax` shorthand method to retrieve html
     // or use `$.getJSON` and a template
     $form_modal.find('.content').load(api_url, function(){
          // html from server exists now
          // run the modal open code here
          $form_modal.modalScriptOpen()
     });
});