我只是在VisualStudio 2012中测试打字稿并且它的类型系统有问题.我的html网站有一个带有id"mycanvas"的canvas标签.我正试图在这个画布上画一个矩形.这是代码
var canvas = document.getElementById("mycanvas");
var ctx: CanvasRenderingContext2D = canvas.getContext("2d");
ctx.fillStyle = "#00FF00";
ctx.fillRect(0, 0, 100, 100);
Run Code Online (Sandbox Code Playgroud)
不幸的是,VisualStudio抱怨说
属性'getContext'在'HTMLElement'类型的值上不存在
它将第二行标记为错误.我认为这只是一个警告,但代码不编译.VisualStudio说
有构建错误.你想继续并运行最后一次成功的构建吗?
我根本不喜欢这个错误.为什么没有动态方法调用?毕竟方法getContext肯定存在于我的canvas元素上.但是我认为这个问题很容易解决.我刚刚为canvas添加了一个类型注释:
var canvas : HTMLCanvasElement = document.getElementById("mycanvas");
var ctx: CanvasRenderingContext2D = canvas.getContext("2d");
ctx.fillStyle = "#00FF00";
ctx.fillRect(0, 0, 100, 100);
Run Code Online (Sandbox Code Playgroud)
但是类型系统仍然不满意.这是新的错误消息,这次是在第一行:
无法将'HTMLElement'转换为'HTMLCanvasElement':类型'HTMLElement'缺少类型'HTMLCanvasElement'的属性'toDataURL'
好吧,我全力以赴静态打字,但这使语言无法使用.类型系统要我做什么?
更新:
Typescript确实不支持动态调用,我的问题可以通过类型转换来解决.我的问题基本上是这个TypeScript的重复:铸造HTMLElement
我已经阅读了很多相关内容,但无法就此主题得出结论.
但我从未使用过PUT或DELETE HTTP Request方法.我倾向于在系统(我的应用程序或网站)的统计数据可能不受影响(如产品列表)时使用GET,并在受影响时使用POST(下订单).是不够还是我错过了什么?
我想只选择一个名为.date的类
出于某种原因,我不能让这个工作.如果有人知道我的代码有什么问题,我将不胜感激.
@$doc = new DOMDocument();
@$doc->loadHTML($html);
$xml = simplexml_import_dom($doc); // just to make xpath more simple
$images = $xml->xpath('//[@class="date"]');
foreach ($images as $img)
{
echo $img." ";
}
Run Code Online (Sandbox Code Playgroud) 我试图废弃一个网站进行练习,但我继续得到HTTP错误403(它认为我是一个机器人)?
这是我的代码:
#import requests
import urllib.request
from bs4 import BeautifulSoup
#from urllib import urlopen
import re
webpage = urllib.request.urlopen('http://www.cmegroup.com/trading/products/#sortField=oi&sortAsc=false&venues=3&page=1&cleared=1&group=1').read
findrows = re.compile('<tr class="- banding(?:On|Off)>(.*?)</tr>')
findlink = re.compile('<a href =">(.*)</a>')
row_array = re.findall(findrows, webpage)
links = re.finall(findlink, webpate)
print(len(row_array))
iterator = []
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
File "C:\Python33\lib\urllib\request.py", line 160, in urlopen
return opener.open(url, data, timeout)
File "C:\Python33\lib\urllib\request.py", line 479, in open
response = meth(req, response)
File "C:\Python33\lib\urllib\request.py", line 591, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python33\lib\urllib\request.py", line 517, in error …
Run Code Online (Sandbox Code Playgroud) 所以今天我想使用该命令创建一个新的 Angular 项目ng new <projectname>
,但出现此错误:
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: project-name@0.0.0
npm ERR! Found: jasmine-core@3.6.0
npm ERR! node_modules/jasmine-core
npm ERR! dev jasmine-core@"~3.6.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer jasmine-core@">=3.7.1" from karma-jasmine-html-reporter@1.6.0
npm ERR! node_modules/karma-jasmine-html-reporter
npm ERR! dev karma-jasmine-html-reporter@"^1.5.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or …
Run Code Online (Sandbox Code Playgroud) 我在我的javascript文件中使用firebase节点api进行Google登录.
firebase.initializeApp(config);
let provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithPopup(provider);
Run Code Online (Sandbox Code Playgroud)
这很好用,用户可以使用他的Google凭据登录.当用户再次访问该页面时,弹出窗口再次打开,但由于他已经登录,弹出窗口关闭而不需要用户进行任何交互.有没有办法在提示弹出窗口之前检查是否已经有登录用户?
我有一个必须执行重复任务的Web应用程序,发送消息和警报,我已经使用脚本页面在浏览器中加载时执行这些任务,即http://example.com/tasks.php和我它在我的Web应用程序的每个页面中都是iframe的意思.
现在我想改变这个以使用CRON作业,因为第一种方法可能会导致卡塞性能,所以我怎么能做一个访问http://example.com/tasks.php的CRON作业.但是,我不希望这个CRON作业创建输出文件,如day.*!
我在共享主机服务上托管应用程序,通过cPanel允许CRON作业.
当我们提到路径时,两个星号而不是一个星号之间的区别是什么?
之前我正在调试我的Spring 3项目.我试图添加一个.swf
<spring:url var="flashy" value="/resources/images/flash.swf"/>
我的web.xml的ResourceServlet看起来像
<servlet-name>Resource Servlet </servlet-name>
<url-pattern>/resources/*</url-pattern>
Run Code Online (Sandbox Code Playgroud)
但不幸的是我收到了这个错误:
WARN org.springframework.js.resources.ResourceServlet - An attempt to access a protected resource at /images/flash.swf was disallowed.
我发现它真的很奇怪,因为images
文件夹中的所有图像都被访问了但是我的.swf怎么会受到"保护"?
后来,我决定改变/resources/*
到/resources/**
最后和它的工作.我的问题是......为什么?
我正在编写一个Web应用程序,根据url前缀的不同,它的行为会有所不同.格式如下:
https://myprefix.mycompany.com
Run Code Online (Sandbox Code Playgroud)
基于myprefix,Web应用程序的行为有所不同.我的网络应用程序从URL中提取该部分并对其进行操作.
但是,当我在本地测试时,我使用localhost地址:
https://localhost:1234
Run Code Online (Sandbox Code Playgroud)
我不会做类似的事情:
https://myprefix.localhost:1234
Run Code Online (Sandbox Code Playgroud)
测试这种情况的最佳方法是什么?
非常感谢