JavaScript inside an lt;img title=quot;lt;a href=#39;##39; onClick=#39;alert(#39;Hello World!#39;)gt;The Linklt;/agt;quot; /gt; possible?(lt;img title=quot;lt;a href=# onClick=alert(Hello World!)gt;The Linklt;/agt;quot; 中的 JavaScript/gt;可能的?)
问题描述
<img title="<a href='#' onClick='alert('Hello World!')>The Link</a>" />
所以我有一些具体的问题.我已经知道我可以使用 TITLE 属性中的属性.但是我可以使用 TITLE 属性中的事件吗?
So I've got some specific question.. I already know that I can work with attributes inside a TITLE attribute.. But can I work with events inside a TITLE attribute?
(顺便说一句 - 这似乎是一个垃圾代码,但这已经在我的 Web 项目中按原样工作了 - 我只需要一种在这个带鞘链接上使用一些 Javascript 的方法.)
(btw - It seems like a rubbish code, but this already works as is should on my web project - I just need a way to use some Javascript on this sheathed link.)
我使用 Jquery 框架.
推荐答案
不,正如你所说的垃圾代码".如果它正常工作,那是因为浏览器试图读懂作者的想法"——换句话说,它们有算法试图理解垃圾代码",猜测可能的意图并在内部将其更改为实际的东西有道理.
No, this is, as you say "rubbish code". If it works as should, it is because browsers try to "read the writer's mind" - in other words, they have algorithms to try to make sense of "rubbish code", guess at the probable intent and internally change it into something that actually makes sense.
换句话说,您的代码只能在偶然的情况下运行,而且可能并非在所有浏览器中都有效.
In other words, your code only works by accident, and probably not in all browsers.
这是你想要做的吗?
<a href="#" onClick="alert('Hello World!')"><img title="The Link" /></a>
这篇关于<img title="<a href='#' onClick='alert('Hello World!')>The Link</a>" 中的 JavaScript/>可能的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:<img title="<a href='#' onClick='alert('Hello World!')>The Link</a>" 中的 JavaScript/>可能的?


基础教程推荐
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01