小编ale*_*s80的帖子

在HTML中显式设置disabled ="false"不起作用

我想在html文件中明确设置一个启用按钮.原因是我的代码稍后将按钮切换为禁用,如果代码崩溃,或者我可能会看到按钮被禁用.

我可以禁用按钮

$("#btn").attr("disabled","true")
Run Code Online (Sandbox Code Playgroud)

但后来一个html包含:

<button id="btn" disabled="false">I want to be enabled!</button>
Run Code Online (Sandbox Code Playgroud)

仍然将按钮显示为已禁用.检查员显示:

<button id="btn" disabled="">I want to be enabled!</button>
Run Code Online (Sandbox Code Playgroud)

我知道我能做到

$("#btn").removeAttr("disabled") 
Run Code Online (Sandbox Code Playgroud)

或类似的,但对html中的许多元素这样做是不方便的.

html disabled-control

24
推荐指数
3
解决办法
5万
查看次数

用python更新python中的Counter集合,而不是字母

如何使用字符串更新计数器,而不是字符串的字母?例如,在使用两个字符串初始化此计数器之后:

from collections import Counter
c = Counter(['black','blue'])
Run Code Online (Sandbox Code Playgroud)

"添加"另一个字符串,如"红色".当我使用update()方法时,它会添加字母'r','e','d':

c.update('red')
c
>>Counter({'black': 1, 'blue': 1, 'd': 1, 'e': 1, 'r': 1})
Run Code Online (Sandbox Code Playgroud)

python collections counter

7
推荐指数
3
解决办法
8042
查看次数

python pandas列名中的下标和上标

是否可以在 Pandas 中格式化列名以具有下标上标?我尝试使用美元作为 $x_a^2$:

import pandas as pd
pd.DataFrame(list([1,2,3]),columns=['$x_a^2$'])
Run Code Online (Sandbox Code Playgroud)

但在 jupyter notebook 中,我得到了一个奇怪的结果 | 最后的性格 在此处输入图片说明

python pandas jupyter-notebook

5
推荐指数
0
解决办法
2803
查看次数

解决错误错误:角度中的“[object Object]”

我对 Angular(版本 6.1.2)很陌生,所以请耐心等待。我正在翻新您可以在 youtube 中找到的 ngSpotify 应用程序,但我在浏览器控制台中遇到了这个错误。

ERROR Error: "[object Object]"
resolvePromisehttp://localhost:4200/polyfills.js:3136:31resolvePromisehttp://localhost:4200/polyfills.js:3093:17scheduleResolveOrRejecthttp://localhost:4200/polyfills.js:3195:17invokeTaskhttp://localhost:4200/polyfills.js:2743:17onInvokeTaskhttp://localhost:4200/vendor.js:34899:24invokeTaskhttp://localhost:4200/polyfills.js:2742:17runTaskhttp://localhost:4200/polyfills.js:2510:28drainMicroTaskQueuehttp://localhost:4200/polyfills.js:2917:25 core.js:1673
defaultErrorLogger
core.js:1673
./node_modules/@angular/core/fesm5/core.js/ErrorHandler.prototype.handleError
core.js:1719
next
core.js:4319:109
./node_modules/@angular/core/fesm5/core.js/EventEmitter.prototype.subscribe/schedulerFn<
core.js:3555:34
./node_modules/rxjs/_esm5/internal/Subscriber.js/SafeSubscriber.prototype.__tryOrUnsub
Subscriber.js:195
./node_modules/rxjs/_esm5/internal/Subscriber.js/SafeSubscriber.prototype.next
Subscriber.js:133
./node_modules/rxjs/_esm5/internal/Subscriber.js/Subscriber.prototype._next
Subscriber.js:77
./node_modules/rxjs/_esm5/internal/Subscriber.js/Subscriber.prototype.next
Subscriber.js:54
./node_modules/rxjs/_esm5/internal/Subject.js/Subject.prototype.next
Subject.js:47
./node_modules/@angular/core/fesm5/core.js/EventEmitter.prototype.emit
core.js:3539:52
onHandleError/<
core.js:3846:48
./node_modules/zone.js/dist/zone.js/</ZoneDelegate.prototype.invoke
zone.js:388
./node_modules/zone.js/dist/zone.js/</Zone.prototype.run
zone.js:138
./node_modules/@angular/core/fesm5/core.js/NgZone.prototype.runOutsideAngular
core.js:3783
onHandleError
core.js:3846
./node_modules/zone.js/dist/zone.js/</ZoneDelegate.prototype.handleError
zone.js:392
./node_modules/zone.js/dist/zone.js/</Zone.prototype.runGuarded
zone.js:154
_loop_1
zone.js:677
./node_modules/zone.js/dist/zone.js/</</api.microtaskDrainDone
zone.js:686
drainMicroTaskQueue
zone.js:6
Run Code Online (Sandbox Code Playgroud)

如何解决?如何理解它来自哪里,并正确捕捉它?我在 angular 的英雄之旅教程中尝试了 handleError 的代码,但没有成功。我找到了类似的帖子,但这对我没有帮助。也许我必须使用Observable,或者找到抛出错误的地方。

代码编译。这是我的服务:

import { Injectable } from '@angular/core';
/*
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { HttpClientModule } from '@angular/common/http';
*/ …
Run Code Online (Sandbox Code Playgroud)

javascript angular

5
推荐指数
1
解决办法
6581
查看次数

Tkinter按钮在悬停在其上后会改变颜色

我创建了一个按钮,我希望在禁用/激活时为白色/红色:

self.btn = tk.Button(cfg.win, text="Button", name = "btn", state="disabled", bg="white", activebackground="red")

self指的是我的Gui类,cfg.win是一个带有.Tk()方法的Tkinter窗口.

然后回调会改变按钮的颜色:

self.btn.configure(state = "active")
Run Code Online (Sandbox Code Playgroud)

按钮变为红色.当我用鼠标悬停在鼠标上时,颜色仍然是红色.但是,当我离开按钮区域时,它变成白色.按钮保持活动状态.我错过了什么?

python tkinter

4
推荐指数
1
解决办法
3578
查看次数

Matplotlib中的条形图在x坐标上具有较大范围时显示较少的条形图

我在这里用python和matplotlib中的条形图做错了什么?第一个图是好的,第二个图在x轴上的范围更广,最大到1500。请注意,在第二个图中,低比例尺上的大多数条消失了,但是未显示1500的条。

我尝试在bar()方法中设置width = 0.8,但这无济于事。

使用对数的x轴(使用plt.xscale('log'))似乎可以正常工作

import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure(figsize=(12, 6))

plt.bar(np.array([1,2,3,4,11,12]), np.array([10,2,1,1,3,10]))
plt.show()
#Then I close the figure and run this:
plt.bar(np.array([1,2,3,4,11,1500]), np.array([10,2,1,1,3,10]))
plt.show()
Run Code Online (Sandbox Code Playgroud)

第一次情节不错 第二情节,不好

python plot matplotlib bar-chart

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

重新采样 Pandas 数据框并合并列中的字符串

我想重新采样一个熊猫数据框并将不同的函数应用于不同的列。问题是我无法正确处理带有字符串的列。我想应用一个将字符串与分隔符(例如“ - ”)合并的函数。这是一个数据示例:

import pandas as pd
import numpy as np
idx = pd.date_range('2017-01-31', '2017-02-03')
data=list([[1,10,"ok"],[2,20,"merge"],[3,30,"us"]])
dates=pd.DatetimeIndex(['2017-01-31','2017-02-03','2017-02-03'])
d=pd.DataFrame(data, index=,columns=list('ABC'))

            A   B          C
2017-01-31  1  10         ok
2017-02-03  2  20      merge
2017-02-03  3  30         us 
Run Code Online (Sandbox Code Playgroud)

使用总和和均值聚合器对数字列 A 和 B 重新采样有效。然而,C 列与 sum 一起工作(但它被放在第二位,这可能意味着某些事情失败了)。

d.resample('D').agg({'A': sum, 'B': np.mean, 'C': sum})

              A               C     B
2017-01-31  1.0               a  10.0
2017-02-01  NaN               0   NaN
2017-02-02  NaN               0   NaN
2017-02-03  5.0        merge us  25.0
Run Code Online (Sandbox Code Playgroud)

我想得到这个:

...
2017-02-03  5.0      merge - us  25.0
Run Code Online (Sandbox Code Playgroud)

我尝试以不同的方式使用 lambda,但没有成功(未显示)。

如果我可以问第二个相关问题:我可以为此做一些后期处理,但是如何用零或“”填充不同列中缺失的单元格?

python resampling pandas

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

Tkinter Entry小部件后的事件回调

从这里的第一个答案: StackOverflow#6548837 我可以在用户键入时调用回调:

from Tkinter import *

def callback(sv):
    print sv.get()

root = Tk()
sv = StringVar()
sv.trace("w", lambda name, index, mode, sv=sv: callback(sv))
e = Entry(root, textvariable=sv)
e.pack()
root.mainloop() 
Run Code Online (Sandbox Code Playgroud)

但是,该事件发生在每个键入的字符上。当用户完成键入并按下Enter键或Entry小部件失去焦点(即用户单击其他位置)时,如何调用事件?

python events tkinter callback

0
推荐指数
1
解决办法
4366
查看次数

Angular 7:防止通过数据绑定传递给子组件的字符串变量中的HTML标签转义

在我的Angular 7应用程序中,我有一个简单的home组件,该组件在字符串变量上使用单向数据绑定(即,我使用@Input和[text]="'Some text'"语法将变量传递给子组件)。

我想在变量中包含html标签(例如链接),并将其呈现在子组件中,但是以下代码由于锚标签而失败。如何解决这个问题?

home.component.ts:

{ Component } from '@angular/core';
@Component({
  selector: 'app-home',
  template: '
    <app-card [text]="'Some text and a link: <a href="https://stackoverflow.com" target="_blank">link</a>'">
    </app-card>
  ',
  styleUrls: ['./home.component.css']
})
export class HomeComponent {}
Run Code Online (Sandbox Code Playgroud)

card.component.ts:

import { Component, Input } from '@angular/core';
@Component({
  selector: 'app-card',
  template: '
    <div class="bla bla">
      <p>{{text}}</p>
    </div>
  ',
  styleUrls: ['./card.component.css']
})
export class CardComponent {
  @Input() text: string;
}
Run Code Online (Sandbox Code Playgroud)

编辑:我写了'templateUrl',但是那是错误的,我的意思是'template'。让我补充一点,我的真实卡片模板比此处显示的div更复杂,并且我实际上在两个组件中都使用templateUrl,如下所示:

templateUrl: './about.component.html', //in app component

templateUrl: './card.component.html',  //in card component
Run Code Online (Sandbox Code Playgroud)

html javascript angular

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