外部 HTML テンプレートをロードするには、jQuery .load() 関数に相当する YUI を使用する必要があります。私が今使っているjQueryコードは -
$('#templates').load('file1.html');
YUI を使用して同じ出力を得るにはどうすればよいですか?
特定の submodule が必要ですが、node-load
表記は同じです。
YUI().use('node', 'node-load', function (Y) {
Y.one('#templates').load('file1.html');
});
jQuery と YUI のすべてのメソッドのすばらしいリストがhttp://www.jsrosettastone.com/にあります。
の正確な代替では$.load(...)
ありませんが、正しい方向に進むことができるかもしれません:
クロスドメインHTMLファイルをロードする唯一の方法は、クロスドメインXMLHttpRequestまたはFlashを使用することです。これらは両方ともYUI3のIOモジュールでサポートされていますが、YUI 2ではサポートされていません。
ソース: http: //yuilibrary.com/forum/viewtopic.php?p = 25704&sid = 33da592b2224850ea738e6947d8dc280#p25704
最後に、HTML をロードするためのソリューションを考案しました。IE および非 IE ブラウザーのケースを処理しました。このようになります -
関数 fName() {
if(navigator.appName == "Microsoft Internet Explorer") {
var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open( "GET", "templates.html", true );
xmlHttp.onreadystatechange = function() {
if( xmlHttp.readyState == 4 && ( xmlHttp.status == 0 || xmlHttp.status == 200 ) )
{
document.getElementById( "div_id_here" ).innerHTML = '"' + xmlHttp.responseText + '"';
}
};
xmlHttp.send();
}
else {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "templates.html", true);
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4 && (xmlHttp.status == 0 || xmlHttp.status == 200))
{
document.getElementById("div_id_here").innerHTML = xmlHttp.responseText;
}
};
xmlHttp.send();
}
}