<!DOCTYPE html> <html> <body> <iframe id="myframe" src="demo_iframe.htm" marginheight="50" marginwidth="50"> <p>Your browser does not support iframes.</p> </iframe> <br><br> <p>The value of the marginheight attribute and marginwidth are: <script> document.write(document.getElementById("myframe").marginHeight); document.write(document.getElementById("myframe").marginWidth); </script> <p> </body> </html>
JS代码获取iframe的marginHeight和marginWidth属性
上面的代码输出:
The value of the marginheight attribute is: 50