ну тогда надо еще кнопки проверять
| Код | <!DOCTYPE html> <html> <head> <title>Светит незнакомая звезда</title> <style type="text/css"> HTNL, BODY { width: 100%; height: 100%; } </style> </head> <body> <script type="text/javascript"> var curId = null; var closeBox = function( id ) { document.getElementById( id ).style.display='none'; curId = null; } var openBox = function ( id ) { if( curId != null ) closeBox( curId ); curId = id; document.getElementById( id ).style.display='block'; } var testBox = function( box, obj ) { while( obj.tagName != 'HTML' ) { if( obj.getAttribute( 'box' ) == box ) return true; obj = obj.parentNode; } return false; } document.onclick = function( e ) { if( curId == null ) return; box = document.getElementById( curId ).getAttribute( 'box' ); e = e || window.event; obj = e.srcElement || e.target; if( !testBox( box, obj )) /* Проверяем, не кликнули ли мы в том блоке, который открыт */ closeBox( curId ); } </script> <input box="box_tool_1" type="button" value="Клац ми" onclick="openBox( 'd1' )" /><br/> <div box="box_tool_1" id="d1" style="position: absolute; left: 100px; top: 10px; border: 1px solid red; display: none">Не работает?</div> <input box="box_tool_2" type="button" value="Клац ми ту" onclick="openBox( 'd2' )" /> <div box="box_tool_2" id="d2" style="position: absolute; left: 150px; top: 40px; border: 1px solid gold; display: none">Совсем не работает?</div> </body> </html>
|
|