简书链接:js判断url中是否有标记参数有就设置divstyledisplayblock
文章字数:1,阅读全文大约需要1分钟
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| html Copy Code <!DOCTYPE html> <html> <body>
<button onclick="checkDebug()">Check Debug</button>
<div id="myDiv" style="display: none;"> This div will only show if debug parameter is present in URL. </div>
<script> function checkDebug() { const urlParams = new URLSearchParams(window.location.search); const debugParam = urlParams.get('debug');
if (debugParam !== null && debugParam.toLowerCase() === 'true') { document.getElementById("myDiv").style.display = "block"; } } </script>
</body> </html>
|