我正在使用这个bootstrap-datepicker作为我的datepicker.我希望datepicker为开始日或默认日选择"今天".我无法弄清楚如何自动设置"今天",所以我做了一个低效的方式
HTML:
<input type="text" value ="today();" id="datepicker"/>
Run Code Online (Sandbox Code Playgroud)
JS:
$('#datepicker').datepicker();
function today(){
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1;
var curr_year = d.getFullYear();
document.write(curr_date + "-" + curr_month + "-" + curr_year);
}
Run Code Online (Sandbox Code Playgroud)
在线样本:http://jsfiddle.net/BXZk2/
只是寻找一个简单的解决方案,使默认日为"今天".
谢谢
发生错误消息时,监视停止.
stream.js:94
throw er; // Unhandled stream error in pipe.
^
source string:51: error: invalid property name
Run Code Online (Sandbox Code Playgroud)
我怎样才能保持手表运行,只是告诉我错误位于何处.
grunt可以处理错误而不需要停止,
styleSheet.scss:41: error: invalid property name
Run Code Online (Sandbox Code Playgroud)
否则,我需要在发生错误时在命令行中输入"gulp".
我对xslt很新,发现它很简单或很复杂.我想澄清一些概念.什么是前兄弟和什么是祖先,从谷歌搜索后,我找到了祖先的解释.并且他们网站上的图表更容易理解.
但我仍然不明白兄弟姐妹
<product>
<inventory>
<drink>
<lemonade>
<price>$2.50</price>
<amount>20</amount>
</lemonade>
<pop>
<price>$1.50</price>
<amount>10</amount>
</pop>
</drink>
<service>
<address />
<phone />
<delivery> City </delivery>
</service>
<snack>
<chips>
<price>$4.50</price>
<amount>60</amount>
</chips>
</snack>
<hotfood></hotfood>
<totalprice> $15</totleprice>
</inventory>
</product>
Run Code Online (Sandbox Code Playgroud)
那我怎么读这个前兄弟:: pop/ancestor :: inventory/totalprice
祖先:: inventory/totalprice = product\inventory\totalprice previous-sibling :: pop - 我不明白这个如何一起阅读?
非常感谢
使用时slideToggle,如何更改文本关闭/显示?我做了一个简单的,但无法将文本更改回来.
这是我做的:
$(document).ready(function(){
$('.open').click(function(){
$('.showpanel').slideToggle('slow');
$(this).text('close');
});
$('.open2').click(function(){
$('.showpanel2').slideToggle('slow');
$(this).text('close');
});
});Run Code Online (Sandbox Code Playgroud)
body{
font-size:20px;
}
#box{
border:2px solid #000;
width:500px;
min-height:300px;
}
.open,.open2 {
width:450px;
height:50px;
background:blue;
margin:5px auto 0 auto;
color:#fff;
}
.showpanel,.showpanel2{
width:450px;
height:300px;
margin:0 auto 10px auto;
background:red;
display:none;
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="box">
<div class="open">Show</div>
<div class="showpanel">This is content</div>
<div class="open2">Show</div>
<div class="showpanel2">This is content</div>
</div>Run Code Online (Sandbox Code Playgroud)
<div class="wrap">
<div class="Level2">Click me</div>
<div class="Level3">Information</div>
</div>
<div class="wrap">
<div class="Level2">Click me</div>
<div class="Level3">Information</div>
</div>
<div class="wrap">
<div class="Level2">Click me</div>
<div class="Level3">Information</div>
</div>
<div class="wrap">
<div class="Level2">Click me</div>
<div class="Level3">Information</div>
</div>
Run Code Online (Sandbox Code Playgroud)
jQuery的
$('.Level2').click(function(){
$('.Level2').closest('.Level3').fadeToggle();
});
Run Code Online (Sandbox Code Playgroud)
我想为fadeIn和fadeOut选择最接近的level3,但是不起作用.我的语法错了吗?在线样本:http://jsfiddle.net/meEUZ/
我没有使用以下语法在ajax中写入条件.
var num = 1;
$.ajax({
type: "POST",
//condition starts
if (num === 1){
url: url1,
data: data1,
}else{
url: url2,
data: data2,
}
//condition finishes
success: success,
dataType: dataType
});
Run Code Online (Sandbox Code Playgroud)
但这种方式有效.
var num = 1;
if(num === 1){
$.ajax({
type: "POST",
url: url1,
data: data1,
success: success,
dataType: dataType
});
}else{
$.ajax({
type: "POST",
url: url2,
data: data2,
success: success,
dataType: dataType
});
}
Run Code Online (Sandbox Code Playgroud)
第二种方法不像重复我的代码那么理想.是我的第一个错误语法的脚本?有人可以指出吗?谢谢
如何将函数a_href = $(this).attr('href');值传递给global a_href,makea_href="home"
var a_href;
$('sth a').on('click', function(e){
a_href = $(this).attr('href');
console.log(a_href);
//output is "home"
e.preventDefault();
}
console.log(a_href);
//Output is undefined
Run Code Online (Sandbox Code Playgroud) 我正在使用jquery的slidetoggle,想要学习如何showup在DIV之外的任何地方单击时隐藏类.谢谢!
在线样本:http://jsfiddle.net/evGd6/
<div class="click">click me</div>
<div class="showup">something I want to show</div>?
Run Code Online (Sandbox Code Playgroud)
$(document).ready(function(){
$('.click').click(function(){
$(".showup").slideToggle("fast");
});
});?
Run Code Online (Sandbox Code Playgroud)
.showup {
width: 100px;
height: 100px;
background: red;
display:none;
}
.click {
cursor: pointer;
}
?
Run Code Online (Sandbox Code Playgroud) 我试图用reduce嵌套数组转换为对象.
我想转换 var bookprice = [["book1", "$5"], ["book2", "$2"], ["book3", "$7"]];
至
var bookpriceObj = {
"book1": "$5",
"book2": "$2",
"book3": "$7"
};
Run Code Online (Sandbox Code Playgroud)
这是我试过的
var bookprice = [["book1", "$5"], ["book2", "$2"], ["book3", "$7"]];
bookpriceObj = {};
bookprice.reduce(function(a, cv, ci, arr){
for (var i = 0; i < arr.length; ++i)
bookpriceObj [i] = arr[i];
return bookpriceObj ;
})
Run Code Online (Sandbox Code Playgroud)
但是以下结果并不是理想的结果
{
["book1", "$5"]
["book2", "$2"]
["book3", "$7"]
}
Run Code Online (Sandbox Code Playgroud) 错误:需要一个条件表达式,但看到一个赋值。( no-cond-assign)
const re = /<%([^%>]+)?%>/g;
let match;
while (match = re.exec('<%hello%> you <%!%>')) {
console.log(match);
}Run Code Online (Sandbox Code Playgroud)
执行while循环来重新分配匹配项,但出现no-cond-assign错误。我仍然可以获得没有错误的输出,但是纠正语法的最佳方法是什么?谢谢