如下代码,在火狐上能正确显示和运行,但是在ie8上则显示有错误,出错提示19行和29行有错误,请问错在哪里?该怎么改?eval那句代码是是什么意思?
<html>
<head>
<script>
var ws = new WebSocket('ws://192.168.1.103:8000/soc');
ws.onmessage = function(event) {
var table = document.getElementById('message');
var data = eval('(' + event.data + ')');
({
'sys': function() {
var cell = table.insertRow().insertCell();
cell.colSpan = 2;
cell.innerHTML = data['message'];
},
'user': function() {
var row = table.insertRow();
row.insertCell().innerHTML = data['message'];
row.insertCell().innerHTML = data['id'];
},
}[data['type']])(); //19行
};
function send() {
ws.send(document.getElementById('chat').value);
document.getElementById('chat').value = '';
}
</script>
</head>
<body>
<input id='chat'>
<from><button onclick='send()'>Send</button></from> //29行
<table id='message' border='1'></table>
</body>
</html>
--
FROM 58.242.155.*