0

XMLファイルを作成し、jQueryでファイルを正常に解析できます。XMLファイルは、セレクターとcss/htmlマニピュレーターのペアで構成されています。

例:これがconsole.logです。

セッションが見つかりました

子セレクターが見つかりました

属性$("。mondaytd.session.m_2_title")

attributes.css( "background-color"、 "#00ffff");

$("。mondaytd.session.m_2_title")。css( "background-color"、 "#00ffff");

サンプルコードは次のとおりです。

    $(xml_Data).find("session").each(function() {
    console.log("found session");
    $(this).children().each(function(){
       var tag = this.tagName;  
       console.log("found child " + this.tagName);
       console.log("attributes" + $(this).text());
       if (this.tagName == "selector"){
            //$(this).next();
            console.log("attributes" + $(this).next().text());
            console.log($(this).text() + $(this).next().text());
            $(this).text() + $(this).next().text();
       }
    });
});

野蛮な楽観主義の発作で、私はこれを考えました:

$(this).text() + $(this).next().text();

スクリプトが連結された文字列をステートメントで実行するようになります。明らかにこれは間違っています。

問題は、xmlデータを組み合わせて、適切なステートメントを作成して実行するにはどうすればよいかということです。

4

1 に答える 1

0

jQueryを使用してタグを作成し、この行($(this).text() + $(this).next().text())の出力をタグに入れて、ドキュメントに挿入する必要があります。

var script=document.createElement('script');
script.type='text/javascript';
$(script).html( $(this).text() + $(this).next().text());
$("body").append(script);
​

または、eval( "code in string here")を使用することもできますが、これはお勧めしません。

または、次のような関数宣言を使用することもできます。var foo = new Function ([arg1[, arg2[, ... argN]],] functionBody)ここで、関数本体はJSコードを含む文字列である必要があります

于 2012-09-10T19:24:52.407 に答える