如何在单击按钮时将 iFrame 中选中的复选框的值序列化到隐藏的表单字段中?

发布于 2024-09-01 04:33:37 字数 598 浏览 4 评论 0原文

我有一个像这样的 iFrame:

<iframe width="100%" frameborder="0" height="470" allowtransparency="true" name="productframe" id="productframe" style="border-bottom:1px solid #eee"></iframe>

iframe 包含从 sql server 数据库提取的几个行项目,我可以选中任何我想要执行任务的复选框 - 在本例中删除它们。我的父文档中有一个按钮,上面写着“删除所选内容”,我希望能够单击此按钮并使用子 iframe 中所选复选框的值填充父页面中的隐藏字段。

我的复选框如下所示:

<input id="Checkbox1" type="checkbox" value="47" title="Select this row" name="selectItem"/>

我的父页面上有一个 jquery 实例,因此我可以使用 jquery 选择器,我只是不知道执行此操作所需的语法。

预先感谢任何可以在这方面帮助我的人。

I have an iFrame like so:

<iframe width="100%" frameborder="0" height="470" allowtransparency="true" name="productframe" id="productframe" style="border-bottom:1px solid #eee"></iframe>

The iframe contains several line items drawn from a sql server db, and I can check any of the checkboxes I want to perform a task with - in this case delete them. I have a button in the parent document that says "Delete selected", and I'd like to be able to click this button and populate a hidden field in my parent page with the values of the selected checkboxes in the child iframe.

My checkboxes look like this:

<input id="Checkbox1" type="checkbox" value="47" title="Select this row" name="selectItem"/>

I have an instance of jquery on my parent page so I can make use of jquery selectors, I just have no clue as to the syntax needed to do this.

Thanks in advance to anyone who can help me on this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拥抱没勇气 2024-09-08 04:33:37

如果这些复选框不在表单中,

var ifr = $('iframe').contents(),
var chb = ifr.find('input:checkbox');

if(chb.length){
   ifr.find('body').append($('<form/>', {
      id:   'tempform',
      css:  {display:none;} 
   }));
   ifr.find('input:checkbox').each(function(){
       ifr.find('#tempform').append($(this).clone());
   }

   var serializedString = ifr.find('#tempform').serialize();      
   // do something with the serializedString
   ifr.find('#tempform').remove();
}

您可以将序列化字符串放入隐藏字段中。嗯,可能有点矫枉过正,但我​​就是有心情这样做:p
这一切都是未经测试的。

if those checkboxes aren't in a form, something like

var ifr = $('iframe').contents(),
var chb = ifr.find('input:checkbox');

if(chb.length){
   ifr.find('body').append($('<form/>', {
      id:   'tempform',
      css:  {display:none;} 
   }));
   ifr.find('input:checkbox').each(function(){
       ifr.find('#tempform').append($(this).clone());
   }

   var serializedString = ifr.find('#tempform').serialize();      
   // do something with the serializedString
   ifr.find('#tempform').remove();
}

and you could put the serializedString into a hidden field. Hmm might be overkill, but I was in the mood for it :p
It's all untested.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文