サーバー側スクリプトを使用してリモート サイトから div コンテナーに html をプルしたいので、jquery を使用してページ上の特定の要素から値をプルできます。例: メタ タグ / ページ タイトルなど。
jQueryセレクターを使用しながら、HTMLが実際に実行されないようにする方法はありますか?
リモート コンテンツをエスケープ可能な json として解析できますか?
ページに追加せずに、HTML を jQuery オブジェクトに直接読み込むことができます。
var jQueryObjectOfRemoteHtml = $('<div>Literally add the HTML like this</div>');
私はそこに 1 つのdiv
タグを配置しましたが、そこにすべてのタグを配置してから、それに対して jQuery 操作を実行し、それを HTML ページに追加することはありません。
はい:
$.get('yoururl/test.html', function(data) {
var html = $(data);
//html is now a queryable jQuery object
//find a div by id:
console.log(html.find("#somediv"));
//iterate all meta tags:
html.find("meta").each(function(){
//do your thing here
});
});