简单教程
提交运行
代码编辑器:
<style> #myDIV{ border:15px solid transparent; width:250px; padding:10px 20px; -webkit-border-image:url(/static/i/javascript/basic/border.png) 30 30 stretch; /* Safari 5 */ -o-border-image:url(/static/i/javascript/basic/border.png) 30 30 stretch; /* Opera 12 */ border-image:url(/static/i/javascript/basic/border.png) 30 30 stretch; } </style> <p>点击“尝试一下”按钮改变 DIV 元素的 border-image 属性:</p> <button onclick="myFunction()">尝试一下</button> <div id="myDIV"> <h1>您好</h1> </div> <script> function myFunction(){ document.getElementById("myDIV").style.borderImage = "url(/static/i/javascript/basic/border.png) 30 30 round"; document.getElementById("myDIV").style.WebkitBorderImage = "url(/static/i/javascript/basic/border.png) 30 30 round"; /* 针对 Safari 5 的代码 */ document.getElementById("myDIV").style.OBorderImage = "url(/static/i/javascript/basic/border.png) 30 30 round"; /* 针对 Opera 12 的代码 */ } </script>
运行结果: