这是从jQuery源代码(1.7.1)开始的摘录:
// Define a local copy of jQuery
var jQuery = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context, rootjQuery );
},
// Map over jQuery in case of overwrite
_jQuery = window.jQuery,
// Map over the $ in case of overwrite
_$ = window.$,
// ...continues...
// [[Class]] -> type pairs
class2type = {};
Run Code Online (Sandbox Code Playgroud)
代码是一系列变量赋值,全部由逗号运算符连接.据我了解逗号运算符,它会在它之前和之后计算表达式,并返回后者的值.
由于变量赋值链没有被分配给任何东西,因此让我感到震惊的是代码可以用分号代替逗号来重写,而不会改变它的运算方式.例如
// Define a local copy of jQuery
var …Run Code Online (Sandbox Code Playgroud) 我试图使用jQuery 绑定play/ pause和ended事件,但有一个问题:
当我右键单击视频并选择播放或暂停时,图标会正确更改.当我单击播放按钮时,它会更改为暂停,但如果我单击暂停按钮继续播放视频,则它不会更改为再次播放.
谁能告诉我哪里出错了?
这是我的代码:
var PlayVideo = function () {
if ($('#video').attr('paused') == false) {
$('#video').get(0).pause();
} else {
$('#video').get(0).play();
}
};
$('#playbtn').click(PlayVideo);
$('#video').click(PlayVideo);
$('#video').bind('play', function () {
$('.playbtn').addClass('pausebtn');
});
$('#video').bind('pause', function () {
$('.playbtn').removeClass('pausebtn');
});
$('#video').bind('ended', function () {
$('.playbtn').removeClass('pausebtn');
});
Run Code Online (Sandbox Code Playgroud)
CSS:
.playbtn {
display: block;
width: 32px;
height: 32px;
margin-left: 10px;
background: url('../images/play.png') no-repeat;
opacity: 0.7;
-moz-transition: all 0.2s ease-in-out; /* Firefox */
-webkit-transition: all 0.2s ease-in-out; /* Safari and Chrome …Run Code Online (Sandbox Code Playgroud) 我对使用h1-h6标题和sectionhtml5 感到困惑.这两个例子中哪一个是正确的?
<body>
<article>
<header>
<h1>Article heading</h1>
<p><time>0/0/00</time></p>
<div id="article-tags"></div>
</header>
<section>
<h2>Introduction</h2>
<p> ... text ... </p>
</section>
<section>
<h2>The problem itself</h2>
<p> ... text ... </p>
</section>
</article>
</body>
Run Code Online (Sandbox Code Playgroud)
这对我来说很自然,将文章分成几个部分,并根据整篇文章标题层次给它们标题,但是
<body>
<article>
<header>
<h1>Article heading</h1>
<p><time>0/0/00</time></p>
<div id="article-tags"></div>
</header>
<section>
<h1>Introduction</h1>
<p> ... text ... </p>
</section>
<section>
<h1>The problem itself</h1>
<p> ... text ... </p>
</section>
</article>
</body>
Run Code Online (Sandbox Code Playgroud)
我已经看到这花了很多时间并且读到每个部分都应该拥有它自己的标题层次结构.
如果第二个例子是正确的,什么是从具有标题的目的h2来h6?如果每个h2都可以在new中分开section并且应该h1再次使用它自己的标题层次结构,那么是否应该使用比标题更低的标题h1(因为它们都可以拥有标题的自己的部分)?
我正在阅读'CouchDB:The Definitive Guide',我对此段感到困惑:
出于演示目的,让CouchDB分配UUID很好.当您编写第一个程序时,我们建议您分配自己的UUID.如果您依赖服务器生成UUID并且最终发出两个POST请求,因为第一个POST请求遭到轰炸,您可能会生成两个文档,但从未发现第一个文档,因为只会报告第二个文档.生成您自己的UUID可确保您永远不会得到重复的文档.
我认为仅当文档创建成功时才保存uuids(特别是_id).也就是说,当我"发布"新文档的插入请求时,会自动生成_id.如果保存文档,则保留该字段,否则丢弃该字段.那不是这样吗?
你能解释一下在CouchDB中生成_id字段的正确方法吗?
我尝试将.brand徽标集中在:
.brand { margin-left: auto; margin-right: auto; }
Run Code Online (Sandbox Code Playgroud)
这是我的顶级导航栏布局:
但它似乎不起作用.
我之前在堆栈上搜索过这个答案,我上面使用的代码来自一个已回答的问题.
知道如何居中.brand?
NB:我不能使用position:absolute and fixed,我想响应地做这个(responsive)
我也试过这个:
.brand {
margin:0 auto !important;
padding:0 auto !important;
position:absolute !important;
right:0px;
left:0px;
z-index:9999999999 !important;
}
Run Code Online (Sandbox Code Playgroud) 我有一个HTML页面,当调整浏览器窗口大小时,它使用CSS和JavaScript将页面内容置于浏览器中间.
当我使用标准HTML5 Doctype声明时,所有浏览器都完全忽略我的CSS文件.我不知道为什么.当我删除HTML5 Doctype时,它们再次正常工作.该页面在Chrome,FF和IE中显示相同(不正确).一切都错了.
这是页面的开头:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="/stylesheet-mobile.jsp" >
<link rel="stylesheet" type="text/css" href="/stylesheet-mobile-frontpage.jsp" >
<meta name="viewport" content="width=device-width" />
<script src="/javascript/jquery/jquery-1.8.3.min.js"></script>
<script src="/javascript/resize-fit.jsp"></script>
<link rel="shortcut icon" href="/favicon.ico" />
</head>
Run Code Online (Sandbox Code Playgroud)
有线索吗?
我想弄清楚如何检查字符串是否以句号结尾,如果不是,则应通过 vanilla JavaScript 添加。有任何想法吗?
我在想这样的事情可能会实际查看变量末尾是否有句号,但它似乎出错了?
此外,目前我不知道如何将句号添加到字符串的末尾。
if todoTitle.str.charAt(str.length-1) != "." {
alert("doesn't end in .");
} else {
alert("does end in .");
};
Run Code Online (Sandbox Code Playgroud)
关于解决此问题的最佳方法的任何想法?谢谢!
给定一个未知维度的div,如何在不使用JavaScript的情况下从一个角到对角线对角绘制实线?
我认为CSS3 calc()功能可能对我有帮助,但似乎你不能将高度和宽度的值拉到另一个属性(例如转换或背景图像)我希望我可以做类似的事情:
transform: rotate ( calc(atan(height / width)) rad);
Run Code Online (Sandbox Code Playgroud)
(计算可能是错误的,但更重要的是语法是完全发明的.)
我针对这个项目瞄准Firefox,但更喜欢适用于任何现代浏览器的东西.
我们如何使用nodeJS中的module.exports返回函数?
file_1 book.js
module.exports = function() {
var points = 0;
return {
rate: function(value) {
points = value;
},
get: function() {
return points;
}
}
}
Run Code Online (Sandbox Code Playgroud)
book.js是根文件.
我们创建两个不同的实例.
但无法获取root.op文件的root方法.
file_2 main.js
var bA = require('./book.js');
var bB = require('./book.js');
bB.rate(10);
bB.get();
Run Code Online (Sandbox Code Playgroud)
输出=> can not find rate and get method.
当我按照Apple的示例进行操作时,总是得到nil activeTab:
override func toolbarItemClicked(in window: SFSafariWindow) {
// This method will be called when your toolbar item is clicked.
window.getActiveTab(completionHandler: { (activeTab) in
print(activeTab)
activeTab?.getActivePage(completionHandler: { (activePage) in
print(activePage)
activePage?.getPropertiesWithCompletionHandler( { (properties) in
print(properties)
if properties?.url != nil {
let urlString = properties!.url.absoluteString
print("URL!", urlString)
let videoURL = self.youtubeDl(urlString: urlString)
if videoURL != nil {
window.openTab(with: videoURL!, makeActiveIfPossible: true, completionHandler: nil)
}
}
})
})
})
}
Run Code Online (Sandbox Code Playgroud)