我有一个iframe,为了访问父元素我实现了以下代码:
window.parent.document.getElementById('parentPrice').innerHTML
Run Code Online (Sandbox Code Playgroud)
如何使用jquery获得相同的结果?
更新:或者如何使用jquery访问iFrame父页面?
我在angular2组件中有一个iframe,我试图通过访问contentWindow来更改iframe的内容.
iframe应该包含一个简单的按钮.
我的代码:
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'component-iframe',
template: '<iframe id="iframe"></iframe>'
})
export class ComponentIframe {
constructor() {
let iframe = document.getElementById('iframe');
let content = '<button id="button" class="button" >My button </button>';
let doc = iframe.contentDocument || iframe.contentWindow;
doc.open();
doc.write(content);
doc.close();
}
}
Run Code Online (Sandbox Code Playgroud)
如果我评论构造函数的代码并启动应用程序,它将编译并正确运行.然后我取消注释并完全运行(按钮出现在iframe中).
如果我取消代码然后启动应用程序(npm start)我有编译错误消息:
类型'HTMLElement'上不存在属性'contentWindow'
.
我还尝试了将costructor的代码放入ngOnInit(),ngAfterContentInit(),ngAfterViewInit()的替代方法,但错误仍然存在.
我需要在URL中编码参数值.如果我使用以下内容:
URLEncoder.encode(url, "UTF-8");
Run Code Online (Sandbox Code Playgroud)
对于这样的URL: http://localhost:8080/...
它将编码"://"等.我需要的是仅对从所有URL字符串开始的参数值进行编码.所以在这种情况下:
我想只编码2个参数值中的"blah"(当然是n个参数).
你最好的方法是什么?
谢谢
随机化
我尝试使用列表编写Prolog程序.但是,我必须使用差异列表,输出应该是:
列表的第i 个元素与列表的第(n-i + 1)个元素相同,n是列表的长度.例如,[a,X,c,b,Y]应该给X = b和Y = a.我在其他问题中找不到类似的回文示例.
到目前为止,我已实施:
% length of the list
len([], 0).
len([H|T], B) :-
len(T, NT),
B is NT + 1.
% return the ith element of the list
match([H|_], 0, H) :-
!.
match([_|T], N, H) :-
N > 0,
N1 is N-1,
match(T, N1, H).
Run Code Online (Sandbox Code Playgroud)
但是,我无法完成.请帮我!
我的代码后面没有输出{{title}} 'hello world'.虽然角度不起作用但没有给出错误信息.
<!-- HTML -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Angular</title>
</head>
<body np-app="myApp">
<div ng-controller="MainController">
{{ title }}
</div>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>`
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
<script type="text/javascript" src="angular.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
// Javascript
var app = angular.module("myApp", []);
app.controller("MainController", ['$scope', function($scope){
$scope.title = "hello world";
}]);
Run Code Online (Sandbox Code Playgroud) 如果'构造函数'在我们创建对象时分配内存并初始化实例变量,那么为什么要说 Object o = new Object();?为什么不 Object o = Object();呢?
新运营商究竟做了什么?