我有一些组div,它们是具有class(es)基于其功能,从这一点,我只是试图让data attribute的first div从last div.所以,我认为这closest符合我的要求.但不幸的是它正在回归null.任何人都可以告诉我我的代码片段有什么问题.
HTML:
<div class="DivApplication">
<div class="DivImg DivImgRun DivImgLeft" data-internalid=16></div>
<div class="DivAppName">Application Title</div>
<div class="DivTime">Created: 23-06-2013 | Edited: 23 July 2013 </div>
<div class="DivImg DivImgReport DivImgRight">report</div>
<div class="DivImg DivImgDelete DivImgRight">delete</div>
<div class="DivImg DivImgEdit DivImgRight">edit</div>
</div>
Run Code Online (Sandbox Code Playgroud)
JQUERY:
$(document).ready(function(){
$(".DivImgEdit").click(function(){
alert($(this).closest('.DivImgRun').data('internalid'));
});
});
Run Code Online (Sandbox Code Playgroud)
结果: NULL
不小心写了如下代码,
var x = {hai:10,test(){ alert("I am alive")}};
x.test(); //alerting the value
Run Code Online (Sandbox Code Playgroud)
它工作正常,我想知道这段代码是如何工作的?因为它以前被认为是无效的语法。而且我知道,在 中ECMAscript 6,已经引入了分配属性的简写。
例子:
var x = 5, y = {x}; // is as same as var x=5,y={x:x};
Run Code Online (Sandbox Code Playgroud)
但我不确定函数定义。任何人都可以用文档中的证据来解释它吗?
我正在使用一个树视图,其中我有许多父节点和子节点..在treeview keydown事件中我使用以下代码在给keydown和keyup时选择下一个节点
Private Sub Treeview1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Treeview1.KeyDown
If e.KeyCode = Keys.Up Then
Treeview1.Select()
ElseIf e.KeyCode = Keys.Down Then
Treeview1.Select()
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
(Treeview1.Select())现在当选择到达第一个节点时,我想重点关注树视图的先前控制,但是我无法检查所选节点是树视图的第一个节点.任何人都可以帮我找到.
我实际上尝试将四个不同的布尔值转换为true/false.
我的情况是,
True false false false Then true else false
false True false false Then true else false
false false True false Then true else false
false false false True Then true else false
Run Code Online (Sandbox Code Playgroud)
我试过这样的,
int a=1;
int b=0;
int c=0;
int d=0;
int cnt=0;
// A block of code will be executed only when any one of the four variables is 1 and
//the rest of them is 0. and another block will be executed when the above mentioned …Run Code Online (Sandbox Code Playgroud) 我有以下JavaScript数组 var arr = ['1', '2', '3', '4' ];
我想将此对象转换为单个字符串,以便我应该生成以下输出:1 + 2 + 3 + 4.这在join功能的帮助下工作正常.
arr.join(' + ') 产生所需的输出.
问题是我的简单数组现在已被转换为复杂对象:
var data = [
{
"key": "1",
"IsData": true
},
{
"key": "2",
"IsData": false
},
{
"key": "3",
"IsData": true
},
{
"key": "4",
"IsData": false
}
];
Run Code Online (Sandbox Code Playgroud)
我可以遍历这个对象并产生所需的结果1 + 2 + 3 + 4.
我想知道是否有更聪明的方式(没有循环)来获得所需的输出.可以使用像lodash或jquery这样的库
通过使用下面的代码,我只是试图用动画效果切换文本阴影,我已经为正向流动做了它,但反向流动不能顺利进行.它恢复没有任何动画效果.任何人都可以帮我解决这个问题吗?
HTML:
<h1>testing testing testing</h1>
<button>glow</button>
<button>unglow</button>
Run Code Online (Sandbox Code Playgroud)
JS:
$(':button:contains(glow)').click(function () {
$('h1').addClass('shadow');
});
$(':button:contains(unglow)').click(function () {
$('h1').addClass('removeShadow');
});
Run Code Online (Sandbox Code Playgroud)
CSS:
h1.removeShadow {
-webkit-animation: removeGlow 1s 1;
-webkit-animation-fill-mode:forwards;
}
@-webkit-keyframes removeGlow {
to {
text-shadow: 1px 0px 0px rgba(0, 0, 0, 0);
}
}
h1.shadow {
-webkit-animation: glow .7s 1;
-webkit-animation-fill-mode:forwards;
}
@-webkit-keyframes glow {
to {
text-shadow:1px 1px 10px rgb(255, 153, 0), 1px 1px 10px rgb(255, 153, 0), 1px 1px 10px rgb(255, 153, 0);
}
}
Run Code Online (Sandbox Code Playgroud)
这个功能有什么作用?
function topRise() {
$(".topRise").animate({
top: "-900px"
}, 25000, topSet);
};
Run Code Online (Sandbox Code Playgroud) function test() {
a = 10;
alert(a);
if (false) {
var a;
}
}
test();
Run Code Online (Sandbox Code Playgroud)
从上面的代码中,您可以看到我在falsy if语句中声明了一个变量,这意味着它内部的代码不会被执行.看,现在变量是不必要的悬挂,为什么会这样......?它会不必要地分配内存.是不是编译器足够聪明地识别它..?或者这些变量是否会像垃圾一样收集垃圾.
给定的代码块将被解释为,
function test() {
var a;
a = 10;
alert(a);
if (false) {
}
}
test();
Run Code Online (Sandbox Code Playgroud)
逻辑上,从变量语句中提取变量的用途是什么?如果在var a;内部分配任何内存,那么这不是一个优化的权利..?
我正在尝试编写一个函数来对这样的数组进行排序:
[
{score:10, name:foo},
{score:-10, name:bar},
{score:0, name:newNAME}
]
Run Code Online (Sandbox Code Playgroud)
进入
[
{rank:1, score:10, name:foo},
{rank:2, score:0, name:newNAME},
{rank:3, score:-10, name:bar}
]
Run Code Online (Sandbox Code Playgroud)
但是我发现很难访问密钥(使用分数对每个对象进行排序和添加排名)。有人可以给我一些提示来编写这样的函数吗?
如何在jquery中将所有输入字段值获取到数组?
请看下面的代码:
<input type="text" name="a" value="a" />
<input type="text" name="b" value="hello" />
<input type="text" name="c" value="world" />
<script type="text/javascript">
function get_fields_values(){
// too much code
var arr=[];
$.each($("input"),function(i,n){
arr.push(n.value)
});
return arr;
// is there any jquery method to get fields values to an array?
// $('input').xxx() ?
}
</script>
Run Code Online (Sandbox Code Playgroud) 我看起来选择otf_itm类,但我在这个特定的页面中使用了两次.我需要使用标签作为选择otf_itm的根.我已经使用了以下工作正常但我想检查并确保它是否是在这种情况下使用的最佳实践.
JS:
$("label[for='town_id']").next().children();
Run Code Online (Sandbox Code Playgroud)
HTML:
<div class="form-group">
<label for="town_id">Town:</label>
<div class="col-md-3 controls">
<div class="otf_itm">
<!-- form items that chagne due to other data -->
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud) 所以当我输入:
function x(z) {
if (z !== 'y') return ("There is an error!")
z = z.replace(/y/g, 'Canada');
return x(z);
}
x('y')
Run Code Online (Sandbox Code Playgroud)
我收到制作"有一个错误".但我想说它是'加拿大'.
我的代码出了什么问题?
谢谢!