简体   繁体   English

iframe中的javascript以访问和修改父级的select元素

[英]javascript in iframe to access and modify select element of parent

I have this line of code that works fine for me: 我有这行代码适合我:

$("#select_mod_completed_project option[value='" + projectname + "']").remove();

it basically just removes one of the options from my select box. 它基本上只是从我的选择框中删除选项之一。 The option to be removed is defined in the 'projectname' js var. 要删除的选项在“项目名称” js变量中定义。 Now this works fine for me when running in a single window but I need to to run from an iframe and the select box will be in the parent of that iframe. 现在,在单个窗口中运行时,这对我来说很好用,但我需要从iframe运行,并且选择框位于该iframe的父级中。

In the parent document, set a function that executes this code: 在父文档中,设置一个执行以下代码的函数:

function removeOption(projectname) {
  $("#select_mod_completed_project option[value='" + projectname + "']").remove();
}

Then just call it from the iframe using window.parent : 然后只需使用window.parent从iframe调用它:

parent.removeOption('test');

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

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