[英]Remove all content between <script type=“JavaScript”>abcd</script> tags
[英]Dynamically remove all content between between script tags of a html file
假設在我的項目主頁中有一些javascript代碼。 例如,
的index.html
<body>
html code here
<script type="text/javascript">
(function () {
some javascript code here
})();
</script>
<button type="button">Delete javascript</button>
</body>
現在,我想要的是,單擊按鈕時,腳本標記之間的所有內容都應與腳本標記一起刪除。 我怎樣才能做到這一點?
您能否嘗試將ID或類放在您的腳本標簽上,然后onlick找到該ID或類並將其刪除? 就像是:
$('button').on('click', function() {
$('#script-tag-id').remove();
});
嘗試這個:
window.addEventListener('load', function() { alert(document.body.innerHTML) document.getElementById('button').onclick = function() { if(document.getElementById('yourScript')){ var script = document.getElementById('yourScript'); document.body.removeChild(script); } alert(document.body.innerHTML); }; });
<body> html code here <script id="yourScript" type="text/javascript"> /*testing*/ </script> <button id="button" type="button">Delete javascript</button> </body>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.