Javascript从[object HTMLDivElement]获取数据

时间:2013-01-11 20:59:42

标签: javascript forms onsubmit

function createChatbox (from) {
console.log(from); //from= Hola
var chatBoxId= from+ 'chatbox';
$('#privateChat').append('<div id="'+ chatBoxId +'" class="chatbox"></div>');
$('#' + chatBoxId).draggable({ handle: '.drag' });
$('#' + chatBoxId).append('<p id="titulo" class="drag">Chat privado con: '+ from +'</p> <div id="'+ from +'textchat" class="textchat"></div><form id="msgPrivate" onsubmit="return formSubmit('+ from +')"><input type="text" id="privateMsg" class="texto" required><input type="submit" class="boton" value="Enviar" class="btnLogIn" id="sendPrivate"> ');
}

function formSubmit (from) {
console.log("entro en formSubmit");
console.log("from es: " +from); //from= [object HTMLDivElement]
sendPrivateMessage(from);
return false;
}

当它转到formSubmit('+ from +')时,from转换为[object HTMLDivElement] 我怎样才能从这个对象中获取数据?

1 个答案:

答案 0 :(得分:0)

解决方案是:

onsubmit="return formSubmit('+'\''+ from +'\''+')"

谢谢!