用到了 select2 組件來多選收件人,用搜狗瀏覽器(6.2版高速模式)在執行到如下這句時報錯(Uncaught InvalidStateError: Failed to read the 'selectionDirection' property from 'HTMLInputElement': The input element's type ('hidden') does not support selection.),6.3版高速和兼容模式都沒問題。
var recipients = JSON.stringify($("select#recipient").select2('data'));
咋一看好像是 input[hidden] 不支持 selection,搞不明白,還是先上 stackoverflow,居然有人遇到同樣的問題
http://stackoverflow.com/questions/25487927/javascript-stringify-object
解決辦法:
//var recipients = JSON.stringify($("select#recipient").select2('data')); //搜狗6.2.5.21637高速模式下報錯 var selectedObjects = $("select#recipient").select2('data'); var dataToSave = []; $.each(selectedObjects, function (index, obj) { dataToSave.push({ "id": obj.id, "text": obj.text }); }); var recipients = JSON.stringify(dataToSave);