Use or || for JS to be compatible with FireFox!_javascript tips
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <li> <a href="http://www.blueidea.com/articleimg/bbsimg/smile.gif"/></a> <a href="图片地址">打开</a> </li> <li> <a href="http://www.blueidea.com/articleimg/bbsimg/biggrin.gif"/></a> <a href="图片地址">打开</a> </li> <li> <a href="http://www.blueidea.com/articleimg/bbsimg/confused.gif"/></a> <a href="图片地址">打开</a> </li> </body> </html> <script language="javascript" type="text/javascript"> document.body.onclick = function(evt){ evt = evt || window.event; var o = evt.target || evt.srcElement; window.open(o.previousSibling.href || o.previousSibling.previousSibling.href); return false; } </script>
Find document.body.onclick = function(evt),
Under IE, this evt will not exist. But under fireFox (it seems to be under opera as well) this parameter will be passed by default. Under IE, this parameter is null. If you want to be compatible, just write it like this.
Continue down,
evt = evt || window.event;
Under IE, evt will point to: window.event, and under fireFox, it will point to the default parameter.
Because under IE, evt || window.event is equivalent to: null || window.event, the result is still window.event
and under fireFox, it is equivalent to evt || null , the result is evt
Next:
o.previousSibling.href || o. previousSibling.previousSibling.href
The former expression is used under IE, and the latter one is used under FireFox.
Because under IE, XMLDom does not have the attribute preserveWhiteSpace, that is, white space is also regarded as a node, and IE The default is false, that is, the blank is not regarded as a node.
The XMLDom mentioned here does not seem to be related to the above, but under FireFox, previousSibling is blank unless there is no space between the two HTML tags. Any form of space.
Open
There is a line break between the two (a type of space), so under FireFox, take the previous node of the next If so, you must use:
o.previousSibling.previousSibling.href
Maybe you still don’t understand it, it doesn’t matter, here is a simple one:
<script> function test(p1,p2,p3){ p1 = p1 || 100; p2 = p2 || "xlingFairy"; return "p1 = " + p1 + " p2 = " + p2 + " p3 = " + p3; } alert(test()); alert(test(null,null,"blueidea.com")) </script>
The above is for JS Or || to be compatible with FireFox!_javascript skills. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!