JavaScript를 사용하여 Html 코드에서 스크립트 태그를 제거하려고합니다. 다음은 HTML 코드입니다.
<script type='text/x-template-handlebars' id='carousel_ui_buttons_next-nav_next'>
<button class="next nav" asg-button>{{{button_text}}}</button>
</script>
나머지 부분은 html 만되도록 스크립트 태그를 제거하고 싶습니다. 브라우저 내에서 코드를 변경해야합니다.
<script>
태그 의 콘텐츠 가 잘못된 자바 스크립트이지만 다음과 같은 방법으로 다음을 수행 할 수 있습니다.
// Function to convert an HTML string to a DOM element
String.prototype.toDOM = function () {
var d = document,
i,
a = d.createElement('div'),
b = d.createDocumentFragment();
a.innerHTML = this;
while (i = a.firstChild) {
b.appendChild(i);
}
return b;
};
// The <script> we wish to replace
var st = document.getElementById('carousel_ui_buttons_next-nav_next');
// Replace it with the <button> that is inside of it
st.parentNode.replaceChild(st.innerHTML.trim().toDOM(), st);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다