2010-12-17 5 views
0

자바 스크립트를 사용하여 특정 div를 페이지에서 새 페이지로 복사하고 있습니다. 새 페이지의 각 테이블에 대한 ID 속성을 제거해야합니다.jQuery 선택기 포커스로 변수

첫 페이지의 내용을 복사하고 있기 때문에 두 번째 페이지에 쓰여지기 전에 문자열에서 ID를 필터링 할 수 있습니다. jQuery가 '포커스'로 변수를 사용할 수 있습니까? DOM 전체를 조작하는 대신 특정 문자열을 조작 하시겠습니까?

당신은 $(html)를 호출하여 jQuery를 객체를 생성을 조작해야
var currentContent = window.open('','currentContentWindow'); 
var htmlToCopy = '<html><head><title></title></head><body>' + window.frames[0].document.getElementById('PageContentPane').innerHTML + '</body></html>'; 

     $("table", htmlToCopy).removeAttr('id'); 

     currentContent.document.open(); 
     currentContent.document.write(htmlToCopy); 
     currentContent.document.close(); 

답변

2

는 다음 html()를 호출하여 HTML을 다시 얻을 :

나는 내가 무슨 말을하는지의 비 작업 버전이있다. 예를 들어

:

var currentContent = window.open('','currentContentWindow'); 
var htmlToCopy = '<html><head><title></title></head><body>' + window.frames[0].document.getElementById('PageContentPane').innerHTML + '</body></html>'; 

var newStructure = $("<div>" + htmlToCopy + "</div>"); 
newStructure.find("table").removeAttr('id'); 

currentContent.document.open(); 
currentContent.document.write(newElements.html()); 

<div> 요소 나 그 내부 HTML을 얻을 당신이 찾고있는 HTML을 얻을 수 있습니다. 문자열로

htmlToCopy = $(htmlToCopy).find("table").removeAttr('id').end().html(); 
1

바로 제거하지 ID=을 모두 함께 DOM을 조작 잊지 :

+1

_Please, ** no ** ._ http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – SLaks

+0

누가 이것을 위해 REGEX를 사용해야합니다. 그냥 "ID ="를 "XX ="같은 의미없는 속성 태그로 바꾸십시오. –