0

thanks so much in advance...here is the problem...

I am trying to add dynamic HTML element (EX. [delete]),everytime on a event call using FBJS.I am able to append the element using following code.

var oldFriendHtml = document.getElementById('friend_container'); var numi = document.getElementById('theValue'); var num = (document.getElementById("theValue").getValue()-1)+2; numi.value = num; var newElementId = "new"+num; var newFriendHTML = document.createElement('div'); newFriendHTML.setId(newElementId); newFriendHTML.setInnerXTML("HTML TO BE ADDED"); oldFriendHtml.appendChild(newFriendHTML);

The problem I am facing is that FBJS parses out the onClick part (event call ) out from the original HTML added .This stops me in the further activity on the added element .It also removes the styling added in the HTML ..

4

1 回答 1

0

关于从 setInnerXHTML 中解析出 onclick,您可以稍后使用 addEventListener 添加事件。

这是一些示例:

var my_obj = document.getElementById('test');
// add a new event listener for each type of event you needed to capture
my_obj.addEventListener('click',my_click_func); // in your case is onclick

function my_click_func(evnt){
   // some action
}

更多细节见http://developers.facebook.com/docs/fbjs#events

于 2010-10-07T20:27:54.413 回答