简体   繁体   English

仅对特定的div执行脚本

[英]Execute script to a particular div only

Till now we are using Iframe to load HTML and script to show the form to the user. 到目前为止,我们使用Iframe加载HTML和脚本以向用户显示表单。

Now, we want to move from Iframe to DIV, but here we have a problem with script. 现在,我们想从Iframe转到DIV,但是这里我们遇到了脚本问题。

Because Iframe is responsible to apply the loaded script to the only iframe, but coming to div script will be loaded into entire HTMLDocument. 因为iframe负责将加载的脚本应用于唯一的iframe,但是div脚本将被加载到整个HTMLDocument中。

Is There any way that loaded script can be applied to that specific DIV only? 有什么方法可以将加载的脚本仅应用于特定的DIV?

Thanks. 谢谢。

First, change your <iframe></frame> to <div></div> after this, you have this way to do this for your CSS(to a certain div): 首先,在此之后将<iframe></frame>更改为<div></div> ,您可以通过这种方式为CSS(至特定div)执行此操作:

#projectName{
style:value;
}

#divAnnounce{

}

The # targets things with ID's if you use a . 如果您使用#,则#定位具有ID的事物。 before it will target the class names, 在定位类名之前,

You can also use both if you need to get specific such as 如果需要具体说明,也可以同时使用两者

#idname.classname{

}

If you have another div inside of the divAnnounce you can do 如果div中有另一个divAnnounce,则可以执行

#divAnnounce #yournewdiv{

}

OR 要么

#divAnnounce div{

}

OR 要么

#newdivid{

}

Notice the space inbetween the two targets saying that they are a parent and child. 注意两个目标之间的空间,说它们是父母和孩子。

For your javascript I don't know with you are using plain javascript or jQuery 对于您的JavaScript,我不知道您使用的是普通javascript还是jQuery

if it is jQuery then you can use jQuery noconflict . 如果是jQuery,则可以使用jQuery noconflict Create separate aliases to use jQuery for example to div1 & div2 创建单独的别名以使用jQuery例如div1和div2

Simple Example: 简单的例子:

    <script>
        var div1Alias = $.noConflict();
        var div2Alias = div1Alias.noConflict();
        jQuery(document).ready(function(){
             alert(div1Alias( "#div1" ).html());
             alert(div2Alias( "#div2" ).html());
        });
    </script>

Try to do this changes in your code and let me know if it helps :) 尝试在您的代码中进行此更改,并告诉我是否有帮助:)

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

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