您好我试图.on将事件绑定到一个元素的直接子节点.
dom看起来像这样
table > tbody > tr+ > td > table > tbody > tr+
到目前为止我已经尝试过
table.find(">tbody").on("dbclick", ">tr", listenerFunction);table.on("dbclick", "> tbody > tr", listenerFunction);这些都不能按预期工作,并且使用table.on("dbclick", "tr", listenerFunction)与嵌套表的碰撞导致双触发器等,因为两个表都有这个监听器.
任何想法最受赞赏.
编辑:HTML
<table>
<tbody>
<tr><!--Selectable row, adds the row after with sub table --></tr>
<tr>
<td>
<table>
<tbody>
<tr></tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud) 我有DOM节点和点击处理程序,我需要在动画时禁用该操作.如何检查元素当前是否正在通过jQuery动画进行动画处理?
$('div').on('click', '.item', function() {
if (/* this not animating */) {
animate($(this));
}
});
Run Code Online (Sandbox Code Playgroud)
我是否需要设置data('play')完成时要清除的元素,或者有更好的方法.
Chrome打包应用程序是否有任何事件监听器来判断应用程序是否已失去焦点?我正在尝试制作游戏,但是当我改变焦点时,我似乎无法暂停游戏.
我尝试了一些不同的东西,如下面的内容,但似乎都没有.
document.onblur = pause;
document.addEventListener('blur', pause, false);
canvas.onblur = pause;
canvas.addEventListener('blur', pause, false);
window.onblur = pause;
window.addEventListener('blur', pause, false);
chrome.app.window.onblur = pause;
chrome.app.window.onBlur = pause;
chrome.app.window.onblurred = pause;
chrome.app.window.onBlurred = pause;
chrome.app.window.addEventListener('blur', pause, false);
chrome.app.window.current().onblur = pause;
chrome.app.window.current().onBlur = pause;
chrome.app.window.current().onblurred = pause;
chrome.app.window.current().onBlurred = pause;
chrome.app.window.current().addEventListener('blur', pause, false);
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?我可以将整个列表复制到我的代码中,而不是一个单独触发暂停.
我迷失了,谷歌有3个结果与一些不相关的东西,然后更多与省略的作品,我发现重要.
嗨,大家好我是第一次建立一个骨干应用程序 - 它很棒!
但是,我不认为我正在以正确的方式为我的模型集合创建视图,当我绑定事件时,它们会为每个视图触发,而我只希望它们为一个视图触发.
这是我的骨干代码(一个片段):
(function(){
Series = Backbone.Model.extend({
defaults:{
active:false
}
});
SeriesGridItemView = Backbone.View.extend({
el:'#model-grid',
defaults: {
active : false
},
initialize: function(){
this.render();
this.listenTo(this.model, 'change', this.setState);
},
render: function(){
this.template = _.template( $('#template-model-grid-item-view').html() );
this.view = $(this.template(this.model.toJSON())).appendTo(this.$el);
},
setState: function(){
this.active = this.model.get('active');
this.view.toggleClass('active',this.active);
},
events: {
'click':'toggle'
},
toggle: function(e){
e.stopPropagation();
e.preventDefault();
console.log('clicked');
return false;
}
});
SeriesCollection = Backbone.Collection.extend({
model: Series,
setPrice : function(p){
this.forEach(function(m){
var active = 0;
_.each(m.get('vehicles'),function(v){
if(v.price <=p){
v.active = true; …Run Code Online (Sandbox Code Playgroud) 众所周知,当我们在javascript中创建一个类时,普通函数返回类对象但事件返回事件对象而类对象丢失
function class(a){
this.name=a;
document.addEventListener('click',this.click,false);
xhr.addEventListener('load',this.xhr,false);
this.normal()
}
class.prototype={
click:function(e){
//e=event,this=theDocument //can't access class
},
xhr:function(e){
//e=event,this=theXHR //can't access class
},
normal:function(e){
//e=null,this=class
}
}
Run Code Online (Sandbox Code Playgroud)
什么是将这些事件绑定到我们班级的最佳方式?
通过最好的方式,我的意思是没有或只是一个小参考,能够以本机方式删除事件(removeEventListener),绝对不会创建内存泄漏.
1.删除一个eventlistener你需要传递该函数作为参考,所以addEventListener('click',function(){alert('something')},false)不起作用.
2.i阅读引用var that=this内部函数创建泄漏,真的吗?
已知方式
function class(a){
this.name=a;
var that=this;// reference
//simply reference the whole object as a variable.
var bindedClick=this.click.bind(this);//bind the click to the class
//(js 1.85)
//can i use removeEventListener('click',bindedClick,false) later?
//apply && call (js 1.3)
}
Run Code Online (Sandbox Code Playgroud)
因为我不是shure如果var that=this(因为它是整个对象)创建泄漏,有时我通过将信息保存到数组中最小化这个并作为参考我使用id ..
var class={};
var id='ID'+Date.now();
class[id].info={here i …Run Code Online (Sandbox Code Playgroud) 由于我不太了解jquery,因此我无法在将鼠标悬停在复选框上时生成一个对话框.任何建议都会有所帮助.下面是我的代码
<input type="checkbox" id="employee-id" name="employeeId" onmouseover="produceDialog()">
<div id="employee-info-div"></div>
Run Code Online (Sandbox Code Playgroud)
同样我的jquery是
produceDialog(){
$("employee-info-div").dialog({
open : function ( event, ui ) {
$(".ui-dialog-titlebar-close").hide();
},
dialogClass : 'fixed-dialog',
resizable : false,
height : 150,
width : 250,
modal : false,
create : function ( event ) {
$(event.target).parent().css('position', 'fixed');
},
});
Run Code Online (Sandbox Code Playgroud)
}
我正在使用模板/把手,但浏览器窗口调整大小时不会触发任何事件处理程序.不确定如何捕获resize事件以动态设置div的高度在视口内
这是我到目前为止使用meteor的事件图尝试的示例:
Template.basic.events({
'resize window' : function(evt, tmpl){
alert("test");
},
};
Run Code Online (Sandbox Code Playgroud)
理想情况下,每次调整窗口大小时都会调用此处理程序,因此我可以使用$(window).height()使用tmpl.find('#main-div')在html中设置div的高度.
编辑:添加代码段.
我是html的新手,我试图在我的网页上显示一个值,当按下按钮时,该值会增加.
这是我的代码
<script type ="text/javascript">
var likesSD = 0;
var dislikesSD= 0;
</script>
<button class="like" onclick="likes++">I like!</button>
<script>document.write(likesSD);</script>
Run Code Online (Sandbox Code Playgroud)
按下按钮时,屏幕上的值不会改变.有没有办法在不使用数据库的情况下做到这一点.
我在富html应用程序中遇到鼠标事件的一些问题.
我有一个很大的"半透明"div覆盖屏幕的一半(该死的设计师).我们叫他A.
在这个A div后面,有一个叫做B.的大容器.
在B内部,有4个div应该响应mouseover和mouseout事件.我们可以称它们为C1,C2,C3和C4.
不幸的是,大胖子A div阻止了我所有的javascript/jquery事件.
这可以解决一些变通方法,但事情就是这样:
我试图处理(有和没有jquery)来自A的事件并将其触发到B.它可以工作,但是B不会将它转发给它的C子,再一次,我不提前知道它们.
非常感谢您的帮助.
我想用jquery中的k,lacs,crores将数字格式化为它们旁边的数字:
1000至1K
1500至1.5K
100000到1Lac
150000至1.5Lac
1000000到10Lac
10000000到1cr等等!
<!DOCTYPE html>
<html>
<head>
<title>Number Differentiation</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(e){
$('#numbr').bind('keypress', function (e) {
return (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57) && e.which != 46) ? false : true;
});
$("#submitBut").click(function(e){
alert(numDifferentiation( $("#numbr").val()))
})
function numDifferentiation($val){
return $val;
}
})
</script>
</head>
<body>
<input id="numbr" type="text"/>
<button id="submitBut">Click</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) javascript ×8
jquery ×6
html ×3
animation ×1
backbone.js ×1
dom ×1
html5 ×1
jquery-ui ×1
meteor ×1
mouseevent ×1