简体   繁体   English

Javascript:如何使用填充了参数的字段打开表单?

[英]Javascript: How to open a form with fields filled with parameters?

I'd like to open a form with its fields filled with data corresponding to a certain record. 我想打开一个表单,其字段填充有与某个记录对应的数据。

Example: 例:

  • Supose a certain form: 假设某种形式:

    Dogs 小狗

      <table id="tabledogs" class="ui-widget ui-widget-content"> <thead> <tr class="ui-widget-header "> <th>ID</th> <th>Name</th> <th>Action</th> </tr> </thead> <tbody> <c:forEach var="dog" items="${sessionScope.dogs}"> <tr> <td width="50%" align="left">${dog.id}</td> <td width="50%" align="left">${dog.name </td> <td><button id="update">Update</button> </td> </tr> </c:forEach> </tbody> </table> </div> 
  • I'd like to open the following form with the corresponding dog data within it (there's other form configurations not showed here for space-saving): 我想打开下面的表单,其中包含相应的狗数据(这里没有显示其他表单配置以节省空间):

      <form> <fieldset> <label for="id">ID</label> <input type="text" name="id" id="id" class="text ui-widget-content ui-corner-all" /> <label for="name">Name</label> <input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all" /> </fieldset> </form> </div> 

For while I have the following JavaScript, wich opens the form but without data: 对于虽然我拥有以下JavaScript,但将打开表单但不包含数据:

$("#update").button().click(function() {
    $("#dialog-form").dialog("open");
});
  • All this stuff are working properly. 所有这些东西都正常工作。 How can I pass dog's data to the form to be shown? 如何将狗的数据传递到要显示的表单? As you probably saw, I have a set of "dog" objects in SessionScope. 如您所见,我在SessionScope中有一组“狗”对象。 Thanks for helping!! 感谢您的帮助!

jQuery有一个.val()函数,可以执行您想要的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM