在我的图像上,我设置了onerror属性,以便在图像由于某种原因不可用时使用占位符:
<img
class="article-img"
src="path-to-image.jpg"
alt="some description"
onerror="this.src='/images/fallback.png'"
>
Run Code Online (Sandbox Code Playgroud)
现在,它看起来onerror 已被弃用,但我找不到任何关于处理错误的建议替代方法的好的来源(可能以类似的紧凑方式)。
知道为什么它被弃用也会很有趣。
我正在为HTML5和CSS3寻找一个好的后备,所以我可以使用它,它在其他浏览器中看起来仍然可以.
A部分:
我知道有很多东西告诉你浏览器是否支持某个HTML5属性,例如http://diveintohtml5.info/detect.html,但他们没有告诉你如何从个人获取类型元素并使用该信息来初始化您的插件.
所以我尝试过:
alert($("input:date"));
//returns "[object Object]"
alert($("input[type='date']"));
//returns "[object Object]"
alert($("input").attr("type"));
//returns "text" ... which is a lie. it should have been "date"
Run Code Online (Sandbox Code Playgroud)
没有人工作.
我最终想出了这个(确实有效):
var inputAttr = $('<div>').append($(this).clone()).remove().html().toLowerCase();
alert(inputAttr);
// returns "<input min="-365" max="365" type="date">"
Run Code Online (Sandbox Code Playgroud)
谢谢:http://jquery-howto.blogspot.com/2009/02/how-to-get-full-html-string-including.html
所以我的第一个问题:1.为什么我不能在不支持html5的浏览器中读取"type"属性?您可以组成任何其他属性和伪造值并阅读它.2.为什么我的解决方案有效?为什么它在DOM中是否重要?
B部分:
以下是我使用探测器的基本示例:
<script type="text/javascript" >
$(function () {
var tM = document.createElement("input");
tM.setAttribute("type", "date");
if (tM.type == "text") {
alert("No date type support on a browser level. Start adding date, week, month, and time …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用从模态返回的数据设置图像源.这是在ng-repeat循环中:
<div id="divNetworkGrid">
<div id="{{network.id}}" ng-repeat="network in networks">
<span>
<table>
<tr>
<td class="imgContainer">
<img ng-src="{{ ('assets/img/networkicons/'+ network.actual + '.png') ||
'assets/img/networkicons/default.png' }}"/>
</td>
</tr>
</table>
</span>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
很明显,当network.actual模型属性返回null时,我想填充default.png.但是我的代码没有拿起默认图像,尽管第一张图像在可用时会很好.
我确定这是一些语法问题,但无法弄清楚是什么问题.
我想使用TouchID验证我自己的应用程序.
1.我希望用户可以点击"输入密码"来调用系统内置密码屏幕进行身份验证,如果成功则输入我自己的应用程序.
但我不知道如何将它转发到密码验证视图,如'case LAErrorUserFallback'中的以下屏幕

这是我的代码:
LAContext *context = [[LAContext alloc] init];
__block NSString *msg;
__block BOOL bAuth;
// show the authentication UI with our reason string
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:NSLocalizedString(@"Unlock APP With FingerPrint", nil) reply:
^(BOOL success, NSError *authenticationError) {
if (success) {
bAuth = YES;
msg =[NSString stringWithFormat:NSLocalizedString(@"EVALUATE_POLICY_SUCCESS", nil)];
dispatch_async(dispatch_get_main_queue(), ^{
[[MYAppDelegate theDelegate] initializeAppAfterKeyVaultUnlocked];
});
NSLog(@"%@",msg);
} else {
bAuth = NO;
switch (authenticationError.code) {
case LAErrorAuthenticationFailed:
msg = [NSString stringWithFormat:NSLocalizedString(@"Authentication Failed", nil)];
// ...
break;
case LAErrorUserCancel: …Run Code Online (Sandbox Code Playgroud) 我正在尝试找到一种实现依赖于第三方库类的服务的好方法.如果库不可用或无法提供答案,我还有一个'默认'实现用作后备.
public interface Service {
public Object compute1();
public Object compute2();
}
public class DefaultService implements Service {
@Override
public Object compute1() {
// ...
}
@Override
public Object compute2() {
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
该服务的实际实现将是这样的:
public class ServiceImpl implements Service {
Service defaultService = new DefaultService();
ThirdPartyService thirdPartyService = new ThirdPartyService();
@Override
public Object compute1() {
try {
Object obj = thirdPartyService.customCompute1();
return obj != null ? obj : defaultService.compute1();
}
catch (Exception e) {
return defaultService.compute1();
}
} …Run Code Online (Sandbox Code Playgroud) java fallback design-patterns strategy-pattern proxy-pattern
为什么IE的后续回退color: red;不起作用?
在IE7中,颜色black不是red.
现场演示
HTML:
<div>
<span>Hello</span>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
div {
width: 200px;
height: 100px;
background-color: blue;
text-align: center;
}
span {
font-size: 2em;
color: red;
color: rgba(250, 250, 97, 0.9);
}
Run Code Online (Sandbox Code Playgroud)
css颜色上的mozilla mdn列出了不同的选项color: value
color: <value>和值可以是关键字red或rgb(255,0,0)rgba(0,0,0,0) 我必须从数据库中获取i18n文本.默认语言是英语,它包含所有内容的文本.但非英语语言不一定具有所有期望的翻译.如果某个实体/密钥的非英语翻译在数据库中不可用,那么我想让它返回英文文本.所以,英语是这里的后备语言.
i18n文本表看起来像这样(PostgreSQL方言):
CREATE TABLE translation (
id SERIAL PRIMARY KEY,
language_code CHAR(2) NOT NULL,
key VARCHAR(20) NOT NULL,
value TEXT NOT NULL,
CONSTRAINT translation_unique UNIQUE (language_code, key)
)
Run Code Online (Sandbox Code Playgroud)
数据如下所示:
INSERT INTO translation
(language_code, key, value)
VALUES
('en', 'foo', 'foo in English'),
('nl', 'foo', 'foo in Nederlands (Dutch)'),
('en', 'bar', 'bar in English')
Run Code Online (Sandbox Code Playgroud)
我想基本上做下面的伪SQL查询:
SELECT key, value
FROM translation
WHERE (language_code = 'nl' OR IF value IS NULL THEN language_code = 'en')
Run Code Online (Sandbox Code Playgroud)
(实际上,该'nl'值是参数化的)
这样它返回以下内容:
+-----+---------------------------+ …
请有人向我解释这行代码的作用:
var list = calls[ev] || (calls[ev] = {});
Run Code Online (Sandbox Code Playgroud)
我最好的猜测:
它使用calls.xxx的值设置变量"list",其中xxx是变量ev.如果调用[ev]不存在,那么它将其创建为空对象并将该空对象分配给"list".是对的吗?
为什么要使用括号?我在哪里可以找到有关使用||的更多信息 何时设置变量,并在此上下文中使用括号?谢谢!
<video controls poster="image.webp">
<source src="video.mp4" type="video/mp4">
</video>
Run Code Online (Sandbox Code Playgroud)
我会使用 WebP 格式的海报,如何为不支持 WebP 的浏览器回退到 JPG?