2010-12-17 6 views
0

JavaScriptを使用して、特定のdivをページから新しいページにコピーしています。新しいページの各テーブルのID属性を削除する必要があります。jQueryセレクタフォーカスとしての変数

最初のページからコンテンツをコピーしているので、2番目のページに書き込まれる前にその文字列からIDを除外できます。 jQueryは変数を「フォーカス」として取り入れることができますか? DOM全体を操作する代わりに、特定の文字列を操作しますか?

私は私が話しているかの非作業バージョンを持っている:

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を取得し、その後、それを操作、$(html)を呼び出すことによって、jQueryオブジェクトを作成する必要があります。例えば

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を取得することができます。

0

まず、jQueryオブジェクトの文字列を作る、それと連携:単なる文字列としてID=を削除し、すべて一緒にDOM操作を忘れない

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

+1

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

+0

REGEXを使用する必要があります。 "ID ="と "XX ="のような無意味な属性タグを入れ替えてください。 –

関連する問題