如何从DOM中卸载包含其所有已定义对象的JavaScript资源?
我开发了一个简单的框架,可以将html片段加载到"主"html中.每个片段都是自包含的,可能包含对其他JS和CSS文件的引用.解析JS和CSS资源并将其动态添加到html中.当从DOM中删除/替换片段时,我想删除它的JS和CSS.
如果我删除了下面示例中的script元素,则page1.js中定义的函数仍然可用.
<html>
<head>
<script src="page1.js" type="text/javascript"></script>
</head>
<body>
...
Run Code Online (Sandbox Code Playgroud)
有没有办法从DOM卸载page1.js对象?
=========我使用的测试代码=======
我尝试了下面评论中的建议; 使用清理功能删除添加的对象 - 但即使这样也会失败.我用于测试的来源:
<html>
<head>
<script type="text/javascript">
function loadJSFile(){
var scriptTag = document.createElement("script");
scriptTag.setAttribute("type", "text/javascript");
scriptTag.setAttribute("src", "simple.js");
var head = document.getElementsByTagName("head")[0];
head.appendChild(scriptTag);
}
function unloadJSFile(){
delete window.foo;
delete window.cleanup;
alert("cleanedup. typeof window.foo is " + (typeof window.foo));
}
</script>
</head>
<body>
Hello JavaScript Delete
<br/>
<button onclick="loadJSFile();">Click to load JS</button>
<br/>
<button onclick="foo();">call foo()</button>
<br/>
<button onclick="unloadJSFile();">Click to unload JS</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
simple.js来源:
var foo = …Run Code Online (Sandbox Code Playgroud) 简而言之我的问题:我如何检测给定用户类/对象是否存在(并且在正确的位置)java注释.
详细的"问题"
可以说我有两个java类:
public class Line {
private List<Cell> cells;
public Line(Object... annotatedObjects) {
// check if annotations @Line and @Cell are present in annotatedObjects.
}
// getter/setter for cells.
}
public class Cell {
// some members
// some methods
}
Run Code Online (Sandbox Code Playgroud)
Line对象包含Cells.
我还有两个注释,如:
public @interface Line {
// some stuff here
}
public @interface Cell {
// some stuff here
}
Run Code Online (Sandbox Code Playgroud)
我还有一堆用户类(本例中有两个用户类),它们包含我指定的@Line和@Cell注释,如:
@Line(name="pqr", schema="three")
public class AUserClass {
@Cell
private String aString;
}
@Line(name="xyz", schema="four")
public class AnotherUserClass { …Run Code Online (Sandbox Code Playgroud) 如何将以下查询表达式转换为相应的C#代码?谢谢.
var list1 = (from ol in orderedList
from er in ol.Er
from rd in er.Rd
where rd.ftr != ""
select ol).ToList<CRInfo>();
Run Code Online (Sandbox Code Playgroud) 如何将这些字符串转换为日期格式并相应地排序....请
2010-11-08 18:58:50.0_getCreated_10180
2010-11-09 17:49:42.0_getCreated_10180
2010-11-09 17:49:42.0_getCreated_10180
2010-11-24 19:44:51.0_getCreated_10180
2010-11-09 13:54:46.0_getCreated_10180
2010-11-23 20:06:29.0_getCreated_10180
2010-11-23 20:06:04.0_getCreated_10180
2010-11-15 17:51:37.0_getCreated_10180
Run Code Online (Sandbox Code Playgroud)
先谢谢你,约瑟夫
我有一个问题,谷歌已经使用错误的网址索引了一些网页.
他们索引的网址是:
http://www.example.com/index.php/section1/section2
Run Code Online (Sandbox Code Playgroud)
我需要它重定向到:
http://www.example.com/section1/section2
Run Code Online (Sandbox Code Playgroud)
.htaccess不是我的强项,所以任何帮助都会非常感激.
提前致谢.
我有一个DataTable,我想检查三列中的值是否唯一.如果不是,则应使用值组合的第一个外观的行号填充最后一列.
例如,这个表:
ID Name LastName Age Flag
-------------------------------------
1 Bart Simpson 10 -
2 Lisa Simpson 8 -
3 Bart Simpson 10 -
4 Ned Flanders 40 -
5 Bart Simpson 10 -
Run Code Online (Sandbox Code Playgroud)
应该导致这个结果:
Line Name LastName Age Flag
-------------------------------------
1 Bart Simpson 10 -
2 Lisa Simpson 8 -
3 Bart Simpson 10 1
4 Ned Flanders 40 -
5 Bart Simpson 10 1
Run Code Online (Sandbox Code Playgroud)
我通过使用两个嵌套for循环迭代DataTable 并比较这些值来解决这个问题.虽然这适用于少量数据,但当DataTable包含大量行时,它会变得非常慢.
我的问题是:这个问题的最佳/最快解决方案是什么,关于数据量可以在100到20000行之间变化?
有没有办法用LINQ做到这一点?(我对它不太熟悉,但我想学习!)
我想制作一个插件,我将用于一些jQuery AJAX加载表数据.
我有一个正确打印数据的函数,但我如何"挂钩"到特定的URL?
比方说,我希望运行该函数,并且每当运行对/mycustomplugin/myurl.php的请求时都要打印数据?(请注意,url /文件不应该存在)
我没有使用WP插件的经验.
C++ 03 5.3.5.3
在第一个替代(删除对象)中,如果操作数的静态类型与其动态类型不同,则静态类型应为操作数的动态类型的基类,静态类型应具有虚拟析构函数或行为未定义.
这就是理论.然而,问题是一个实际的问题.如果派生类没有添加数据成员怎么办?
struct Base{
//some members
//no virtual functions, no virtual destructor
};
struct Derived:Base{
//no more data members
//possibly some more nonvirtual member functions
};
int main(){
Base* p = new Derived;
delete p; //UB according to the quote above
}
Run Code Online (Sandbox Code Playgroud)
问题是:这是否存在真正危险的现有实施? 如果是这样,你能否描述一下如何在该实现中实现内部代码,使代码崩溃/泄漏或其他什么?我请求你相信,我发誓,我无意依赖这种行为:)
我想获得方法,但有一个超载.例如在对象中,我试图获得"等于".使用时
public virtual bool Equals(object obj);
public static bool Equals(object objA, object objB);
Run Code Online (Sandbox Code Playgroud)
写给typeof(Object).GetMethod("Equals")我一个例外,写得typeof(Object).GetMethod("public virtual bool Equals(object obj)")让我无效.在这种情况下,如何指定我想要的方法?
c# ×3
javascript ×2
reflection ×2
.htaccess ×1
.net ×1
annotations ×1
apache ×1
arrays ×1
c ×1
c++ ×1
constructor ×1
datatable ×1
datetime ×1
dom ×1
java ×1
linq ×1
mod-rewrite ×1
performance ×1
php ×1
pthreads ×1
runtime ×1
sorting ×1
string ×1
vb.net ×1
wordpress ×1