小编H. *_*lyn的帖子

TypeScript 中的“string[]”类型不存在“includes”

从这个问题和接受的答案中,我知道有一种方法可以使用以下代码行检查数组是否包含 JavaScript 中的对象

> ['joe', 'jane', 'mary'].includes('jane');
true 
Run Code Online (Sandbox Code Playgroud)

但是,如果我在TypeScript 中使用相同的代码,则会出现此错误:

属性includes在 type 上不存在string[]

  1. 为什么给编译器这个错误?我期待 JS 中可用的所有内容都可以在 TS 中使用。
  2. 如何在不更改代码的情况下解决此错误?它必须在 ES5 上工作。

arrays ecma typescript

3
推荐指数
1
解决办法
3958
查看次数

C# XML 文档注释中的不同颜色

我试图在 XML 文档注释中使用不同颜色的文本,如下图所示,“true”、“false”和“Window”一词的颜色为蓝色和绿色。

彩色 XML 文档注释

我尝试反编译包含这些内容的代码,但 xml 文档不同,并且 Microsoft 文档中也没有提及这种颜色。

c# xml-documentation xml-comments visual-studio

3
推荐指数
1
解决办法
3404
查看次数

以纯文本格式查找URL并插入HTML A标记

我有带URL的文本,我需要用HTML A标记来包装它们,如何在c#中做到这一点?

例如,我有

My text and url http://www.google.com The end.
Run Code Online (Sandbox Code Playgroud)

我想得到

My text and url <a href="http://www.google.com">http://www.google.com</a> The end.
Run Code Online (Sandbox Code Playgroud)

html c# text-manipulation

2
推荐指数
1
解决办法
4245
查看次数

如何编辑所有特殊html标签的属性(如a)

我正在尝试使用c#编辑所有特殊html标记的属性(如a).例如,我想更改此代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Untitled Page</title>
</head>
<body>
    <a href="http://google.com"></a>
    <a href="http://gmail.com"></a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

对此:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Untitled Page</title>
</head>
<body>
    <a href="http://go.go/default.aspx?url=http://google.com">
    </a><a href="http://go.go/default.aspx?url=http://gmail.com"></a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

这意味着我想追加hrefin 的值<a>

我尝试过LinqToXML,但它不起作用,因为HTML不是有效的XML(因为DOCTYPE标记)

这是我的代码:

XDocument xmlFile = XDocument.Load(s);

var query = from c in xmlFile.Elements("html").Elements("body").Elements("a")
            select c;

foreach (XElement book in query)
{
    string atr = book.Attribute("href").Value;
    book.Attribute("href").Value = "http://ahmadalli.somee.com/default.aspx?url=" + atr;
} …
Run Code Online (Sandbox Code Playgroud)

html c# asp.net c#-4.0

2
推荐指数
1
解决办法
1624
查看次数

在JavaScript中向现有数组添加新值

我在JavaScript中定义了一个Array List:

var arrListContainer = [];
var emptyArray = [];
for (var i = 0; i < 5; ++i) {
    arrListContainer.push(emptyArray);
}
Run Code Online (Sandbox Code Playgroud)

list的默认值是: [[], [], [], [], []]

我想增值arrListContainer[2],所以:

arrListContainer[2].push("a");
Run Code Online (Sandbox Code Playgroud)

结果为什么[["a"], ["a"], ["a"], ["a"], ["a"]]

我不明白.我只需要[[], [], ["a"], [], []]

谢谢!

javascript

2
推荐指数
1
解决办法
590
查看次数

调整浏览器窗口大小时,使Canvas动态调整大小

我在网页上设置了一个画布,其中运行着js动画,该动画填充了整个浏览器窗口,但是当我调整窗口的大小时,似乎无法自动调整画布的大小以适应新的窗口大小。有人可以告诉我我需要添加到我的js中才能正确获得此功能吗?谢谢!

var canvas = document.getElementById('canvas');
var makecodeplay = canvas.getContext('2d');
canvas.width=window.innerWidth;
canvas.height=window.innerHeight;

makecodeplay.clearRect(0, 0, canvas.width, canvas.height);
makecodeplay.fillStyle = "rgb(75,77,81)";
makecodeplay.fillRect(0, 0, canvas.width, canvas.height);

function randomPaint(inX, inY) {
   
    var x = Math.floor(Math.random() * canvas.width);
    var y = Math.floor(Math.random() * canvas.height);
    var r, g, b;
    r = Math.floor(Math.random() * 255);
    g = Math.floor(Math.random() * 255);
    b = Math.floor(Math.random() * 255);
    makecodeplay.beginPath();
    makecodeplay.fillStyle = "rgba(35,37,41,0.3)";
    makecodeplay.fillRect(0, 0, canvas.width, canvas.height);
    makecodeplay.fill();
    makecodeplay.closePath();

    makecodeplay.beginPath();
    makecodeplay.strokeStyle = "rgba(" + r + "," + g + "," + …
Run Code Online (Sandbox Code Playgroud)

javascript html5

2
推荐指数
2
解决办法
3465
查看次数

无法对齐两个html5输入范围

这是我的htm5代码。两个输入范围未正确对齐。如何正确对齐这两个元素?

   <!DOCTYPE html>
<html lang="it">
<head>
  <title>Ciao</title></head>
<body>
  <fieldset>
    <legend>Your Indicators</legend>
	<label for="height">Height::</label>
    <span>Short</span>
    <input type="range" id="height" min="0" max="100" name="height" />
    <span>Tall</span><br>
	<label for="salary">Salary::</label>
    <span>Poor</span>
    <input type="range" id="salary" min="0" max="100" name="salary" />
    <span>Rich</span>
    </label>
  </fieldset>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

html css html5

2
推荐指数
1
解决办法
1622
查看次数

YouTube API始终为不同的查询提供相同的视频

我正在建立一个从YouTube加载视频的网站.问题是,当我使用其他查询时,我总是得到相同的视频.如果我使用下面的查询,结果在两种情况下都是相同的.

  1. 用'plop'

    https://www.googleapis.com/youtube/v3/search?part=snippet&key=my_key&q=plop 
    
    Run Code Online (Sandbox Code Playgroud)

    惠特噗

  2. 使用'K3':

    https://www.googleapis.com/youtube/v3/search?part=snippet&key=my_key&q=k3
    
    Run Code Online (Sandbox Code Playgroud)

    惠特K3

这是我的代码:

$("body").ready(function () {
    init();
});

function init() {
    $("#search-button").click(function () {
        $.ajax({
            url: "https://www.googleapis.com/youtube/v3/search?part=snippet&key=my_key&q=" + $("#query"),
            success: function (data) {

                //data = JSON.parse(data);
                var lengte = data.items.length;

                $("#search-container").empty();

                for(var i = 0; i < lengte; i++) {

                    $("#search-container").append('<iframe width="427" height="240" src="https://www.youtube.com/embed/' + data.items[i].id.videoId + '" frameborder="0" allowfullscreen></iframe>');
                }
                console.log(data);
            },
            error: function() {
                console.log("oops");
            }
        });
    });
}
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="buttons">
    <label>
        <input id="query" type="text"/>
        <button id="search-button" >Search</button>
    </label>
</div>
<div id="search-container"></div>
Run Code Online (Sandbox Code Playgroud)

javascript jquery youtube-api

2
推荐指数
1
解决办法
173
查看次数

使用Dropzone.JS将图像上传到Imgur

我已经创建了一个页面,网站的用户可以通过拖放来上传图片.为此,我使用Dropzone.JS (转到infositeGithub),我将文件上传到Imgur.

问题是我不知道如何用DropZone.JS做到这一点.这是我用于实现Dropzone-class的代码.

<div class="dropzone">
    <div class="fallback">
        <input name="file" type="file" multiple />
    </div>
</div>

<script src="~/Scripts/DropZone.js" type="text/javascript"></script>    

<script>
    var myDropzone = new Dropzone(".dropzone", { 
        url: "https://api.imgur.com/3/image", 
        Authorization: 'Client-ID MY_CLIENT_ID'
    });
</script>
Run Code Online (Sandbox Code Playgroud)

以下是我从Imgur得到的回复

{
    "data": {
        "error": "An image ID is required for a GET request to /image",
        "request": "/3/image",
        "method": "GET"
    },
    "success": false,
    "status": 400
}
Run Code Online (Sandbox Code Playgroud)

出现此错误:

XMLHttpRequest无法加载https://api.imgur.com/3/image.预检响应中Cache-Control不允许请求标头字段Access-Control-Allow-Headers.

如果请求成功,我也会从Imgur获取上传图像的URL.

javascript imgur dropzone.js

2
推荐指数
1
解决办法
1384
查看次数

找不到与给定名称匹配的资源(在'主题'中,值为'@ android:style/Theme.my_theme').(APT0000)

我最近安装了Xamarin Android全新版本(版本5.10.1 build 6).当我尝试添加主题时,我遇到了可怕的"找不到资源..."错误.
这是我试图添加的第一个主题,所以我不确定问题是否可能是由于我在代码中编写的内容.然而,在StackOverflow和Xamarin论坛上搜索,我发现这个问题可能意味着没有安装某些Android库.

所以我已经安装了来自最新和以前的API以及Extras的更多东西,但我仍然得到同样的错误.
该应用程序只是一个针对手机的简单应用程序,所以我没有安装磨损或电视库.我还需要多久才能使用Android API?
还有什么我应该安装的并不明显吗?

对于这个特定的错误,已经有很多答案,但是其中很多都是模糊的,并没有给出确切的说明,或者提到我不认识的组件,我想是因为我使用的是Xamarin.

这是我的主题代码.

<?xml version="1.0" encoding="UTF-8" ?>
<resources>
  <style name="Theme.my_theme" parent="@android:style/Theme.DeviceDefault.Light.DialogWhenLarge">
    <item name="android:textColor">#00FF00</item> <item name="android:typeface">monospace</item> <item name="android:textSize">20sp</item>
  </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

这是清单.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="My_app.My_app">
    <uses-sdk android:minSdkVersion="17" />
    <application android:label="My_app" android:theme="@android:style/Theme.my_theme" android:icon="@drawable/icon"></application>
</manifest>
Run Code Online (Sandbox Code Playgroud)

以下是显示已安装内容的Android管理器.有没有明显没有安装的东西?

androidmanager1 androidmanager2 androidmanager3 androidmanager4

android android-theme xamarin

2
推荐指数
1
解决办法
3200
查看次数