未捕获的TypeError:对象#没有方法'alert'(Uncaught TypeError: Object # has no method 'alert')
问候社区,我是javascript的新手,我想弄清楚为什么这段代码会把这个错误抛给我,谢谢!
"use strict"; var myFunction = function(){ document.alert("hola"); }; myFunction();
控制台(chrome)说:
未捕获的TypeError:对象#没有方法'alert'
我使用jshint来纠正任何sintax错误,但它似乎没有错误。
Greetings to the community, i'm new in javascript and i want to figure out why this code throws me this error, thank you!
"use strict"; var myFunction = function(){ document.alert("hola"); }; myFunction();
the console(chrome) says:
Uncaught TypeError: Object # has no method 'alert'
I've used jshint to correct any sintax errors, but it seems to have no errors.
原文:https://stackoverflow.com/questions/18600258
更新时间:2023-09-28 12:09
最满意答案
真的最好的方法是为onFocus事件设置一个处理程序,然后将变量设置为具有焦点的元素的ID。
这样的事情
var id; $(":input").focus(function () { id = this.id; });
Really the best way to do it is to setup a handler for the onFocus event, and then set a variable to the ID of the element that has focus.
something like this:
var id; $(":input").focus(function () { id = this.id; });
相关问答
更多-
真的最好的方法是为onFocus事件设置一个处理程序,然后将变量设置为具有焦点的元素的ID。 这样的事情 var id; $(":input").focus(function () { id = this.id; }); Really the best way to do it is to setup a handler for the onFocus event, and then set a variable to the ID of the element that has focus. ...
-
在你的点击事件中使用jQuery的.stopPropagation() : $('.content').click(function(e){ e.stopPropagation(); }); 编辑 :我已经使用.mouseenter()和.mouseleave()更新了jsFiddle来设置一个忽略标志。 use jQuery's .stopPropagation() on your click event: $('.content').click(function(e){ e.stopP ...
-
// Get the focused element: var $focused = $(':focus'); // No jQuery: var focused = document.activeElement; // Does the element have focus: var hasFocus = $('foo').is(':focus'); // No jQuery: elem === elem.ownerDocument.activeElement; 你应该使用哪一个? 引用jQuer ...
-
jquery选择当前元素(Jquery Select Current Element)[2022-05-18]
尝试这样的事情: $('a.newsbox').hover( function(){ $(this).find('div').fadeToggle(); }); 通过使用fadeToggle ,“阅读更多”也将隐藏在mouseout上。 Try something like this: $('a.newsbox').hover( function(){ $(this).find('div').fadeToggle(); }); By using fadeToggle, "read more" w ... -
使用last() 。 你也可以使用:last选择器,但是它不能直接传递给浏览器的选择器引擎。 $("audio").last() 为什么不是last-of-type工作? 选择器的jQuery文档说: 选择同一元素名称的兄弟姐妹中最后一个元素。 因此,在您的情况下,它将匹配其他元素内的所有最后audio元素。 Use last(). You could use the :last selector too, but then it can't be passed directly to the brows ...
-
您可以使用:visible selector和first() ,如下所示 $('#A:visible, #B:visible').first().focus(); $('#A:visible, #B:visible')将选择ID为A和B且当前可见的元素,因此基本上只选择/过滤来自给定ID的可见元素。 first会从匹配的集合中获取第一个元素 focus将设置要关注的元素。 You can use :visible selector and first() as follow $('#A:visible, ...
-
你可以使用jQuery blur() 功能,它将移除焦点元素中的焦点。 $("#focus").click(function(){ $("input").focus(); }); $("#blur").click(function(){ $("input").blur(); });var focusedElement = $(':focus'); var focusedElement = $(':focus');
相关文章
更多- 如何在runtime重载javascript alert函数
- Object Oriented Programming
- Guava学习笔记:复写的Object常用方法
- 研磨设计模式之工厂方法模式(Factory Method)-模式讲解1
- 研磨设计模式之工厂方法模式(Factory Method)-模式讲解2
- 研磨设计模式之工厂方法模式(Factory Method)-场景问题
- 研磨设计模式之工厂方法模式(Factory Method)-模式讲解3
- Cannot expose request attribute 'website' because of an existing model object of the same name 的解决方案
- 研磨设计模式之工厂方法模式(Factory Method)-解决方案
- 不显示删除回复显示所有回复显示星级回复显示得分回复 请问java Object的hashcode()方法是怎么实现的啊,内部的算法是什么啊
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)