2016-08-21 25 views
0

私の先生がコードを 以下に変更しましたが、動作しません。どのように動作して解決するのか理解できません。setAttributeのJavascript

function _$(e, attrs) { 
 
    var el = document.createElement(e); 
 
    for(a in attrs){ 
 
     el.setAttribute(a, attrs[a]); 
 
    } 
 
} 
 

 
    var $taskMain = _$("section", { "class": "sdfjsf", "id": "taskId", "data-id-number": "sajfsaf"}); 
 

 
//and i have error 
 
//template.js:80 Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'. 
 
    currentCollon.appendChild($taskMain);

答えて

2

私はあなたの_$関数の最後にreturn el;が欠けていると思います。

+0

thx私はそれを修正して良いです! –

+1

@guntars:あなたはsmarxの答えを受け入れるべきです。 –

-1

_$機能の最後にreturn el;がありません。

次のように結果を与える、_$関数が実行前にタグ

<section class="sdfjsf" id="taskId",data-id-number:"sajfsaf"></section> 

この文コード

currentCollon.appendChild($taskMain); 

を作成し、currentCollonを実行した後、本体

<body> 
</body> 

であると仮定する

<body> 
<section class="sdfjsf" id="taskId",data-id-number:"sajfsaf"></section> 
</body> 
+0

どのような構文が 'id =" taskId "、data-id-number:" sajfsaf "'ですか? –

+0

大変申し訳ございませんが、

関連する問題