草庐IT

event_type

全部标签

javascript - Ember : nested components events bubbling

我创建了一组嵌套组件。代码在这里:http://emberjs.jsbin.com/hasehija/2/edit.HTML:{{#level-1}}{{#level-2}}{{#level-3}}Clickme(yielded){{/level-3}}{{/level-2}}{{/level-1}}JS:App.ApplicationController=Ember.Controller.extend({actions:{handleAction:function(){alert('HandledinApplicationController');}}});App.Level1Com

javascript - Jquery:如何使用 <input type "value"> 字段的 ="file"动态显示图像

我想知道是否有一种方法可以动态显示用户刚刚上传到inputtype="file"字段的图像。例如,到目前为止我有以下代码:image_upload.html上传.js$(document).ready(function(){$("#id_image").change(file_select);});functionfile_select(event){$("#uploaded_image").attr("src",$("#id_image").val());}所以我基本上想显示用户刚刚上传到Field上的图片。当然,我知道如果用户已经提交表单并且图像已经在我的数据库服务器中,我可以轻松

javascript - "Input type file.files"选择器在 jQuery 中不起作用

我正在尝试使用以下代码在HTML输入中获取有关正在上传的文件的信息:$(document).ready(function(){$('#btn').on('click',function(){file_size=$("#my_file").files[0].size;alert(file_size);});});但是不行,控制台返回:$("#my_file").filesisundefined 最佳答案 $("#my_file")是一个jQuery对象,jQuery对象没有属性files...要从jQuery中获取DOM元素,请执行$

javascript - 为什么 event.clientX 在 firefox 中对于 dragend 事件错误地显示为 0?

来自dragend的警报将​​mouseX显示为零,无论它当前位于何处。这在Chrome中运行良好,所以不确定我做错了什么。functionmove(e,obj,but){if(typeof(obj)==='string'){obj=document.getElementById(obj);}if(typeof(but)==='string'){but=document.getElementById(but);}//elementCoord(but);//getthecurrentcoordsofthebutton&elementCoord(obj);//thecontainere=e

javascript - 跨浏览器意外访问 "event"变量?

首先让我说我知道下面的代码有一个主要问题。具体来说,event参数不会传递到函数中。我不明白的是为什么在下面的代码中,Chrome、Opera、Safari、Firefox和IE都以不同的方式处理event变量。$('#eventBtn').on('click',function(){console.log(event);event.preventDefault();});在Chrome、Opera和Safari中,上述代码有效。IE在第二行失败,Firefox立即失败。出于测试目的,我创建了一个稍微更漂亮的jsFiddle.以上console.log(event)在各种浏览器中的输出

javascript - 巴别塔 : Function parameter types in ES6

如果我编写以下代码并通过Babel(6.5.0)转译它,它会正常工作。functionfoo(first:string,second:number){//codehere}:string和:number只是从转译的ES5代码中删除。如果我使用错误的参数类型调用该函数,它不会导致任何错误/警告。即使没有任何功能,它们也能提供信息。我无法在互联网上找到有关ES6参数类型的正确信息。参数类型甚至是ES6的一部分吗?编辑:这个问题在下面的评论中得到了回答,我根据他们总结了官方答案。 最佳答案 感谢JoeClay,Bergi和FelixKli

javascript - 跨浏览器 : detect blur event on window

我刚刚阅读,我认为所有与此主题相关的线程,但我找不到真正解决我的问题的方法。我需要检测浏览器窗口何时失去焦点,即模糊事件。我已经尝试了stackoverflow上的所有脚本,但似乎没有合适的跨浏览器方法。Firefox是这里有问题的浏览器。使用jQuery的常见方法是:window.onblur=function(){console.log('blur');}//OrthejQueryequivalent:jQuery(window).blur(function(){console.log('blur');});这适用于Chrome、IE和Opera,但Firefox未检测到该事件。是

javascript - 松弛传入 webhook : Request header field Content-type is not allowed by Access-Control-Allow-Headers in preflight response

我尝试在浏览器中通过fetchAPI发布slack消息:fetch('https://hooks.slack.com/services/xxx/xxx/xx',{method:'post',headers:{'Accept':'application/json,text/plain,*/*','Content-type':'application/json'},body:JSON.stringify({text:'Hithere'})}).then(response=>console.log).catch(error=>console.error);};我收到以下错误消息:FetchA

javascript - 在 jQuery 中,event.currentTarget 总是等于 $(this) 吗?

这句话总是正确的吗?$("p").click(function(event){alert(event.currentTarget===this);});一种方法优于另一种方法吗?我喜欢使用$(this)而不是event.currentTarget但在某些情况下可以做得更好吗?哪个更好?完全一样吗?另一个细微差别-当检查Firebug时console.log(this)和console.log($(this))给了我完全相同的元素。如果它们相同-有什么不同?(因为我知道我可以写这个$(this).css('color','white')但不能写this.css('color','whit

javascript - 在 event.target 上使用 jQuery 方法

我想在click事件期间检查事件目标的特定属性:$('div').on('click',function(e){console.log(e.target.attr('class'));});这会导致浏览器控制台出错:main.js:47UncaughtTypeError:e.target.attrisnotafunctionevent.target不也是一个jQuery对象吗? 最佳答案 e.target默认情况下不是jQuery对象,它是DOM元素。你必须施放它:$(e.target).attr('class')工作示例:$('d