我有數據庫,目前使用中的表 第一個問題是與格式化文本的粘貼,但似乎聯編輯,這一問題被固定在90%,與此腳本:REPLACE()標籤不工作在JavaScript
<script type="text/javascript">
var _onPaste_StripFormatting_IEPaste = false;
function OnPaste_StripFormatting(elem, e) {
if (e.originalEvent && e.originalEvent.clipboardData && e.originalEvent.clipboardData.getData) {
e.preventDefault();
var text = e.originalEvent.clipboardData.getData('text/plain');
window.document.execCommand('insertText', false, text);
}
else if (e.clipboardData && e.clipboardData.getData) {
e.preventDefault();
var text = e.clipboardData.getData('text/plain');
window.document.execCommand('insertText', false, text);
}
else if (window.clipboardData && window.clipboardData.getData) {
// Stop stack overflow
if (!_onPaste_StripFormatting_IEPaste) {
_onPaste_StripFormatting_IEPaste = true;
e.preventDefault();
window.document.execCommand('ms-pasteTextOnly', false);
}
_onPaste_StripFormatting_IEPaste = false;
}
}
</script>
我的PHP代碼如下所示:
<td contenteditable='true' onblur=saveToDatabase(this,'titleeng','".$data['id']."') onClick='showEdit(this);' onpaste='OnPaste_StripFormatting(this, event);'>".$data['titleeng']."</td>
腳本刪除標籤,但保留
,這導致我的SQL AJAX失敗
這是Ajax的腳本:
<script>
function showEdit(editableObj) {
$(editableObj).css("background","#FFF");
}
function saveToDatabase(editableObj,column,id) {
$(editableObj).css("background","#12ff65 url(loaderIcon.gif) no-repeat right");
$.ajax({
url: "saveedit.php",
type: "POST",
data:"column="+column+"&editval="+editableObj.innerHTML+"&id="+id,
success: function(data){
$(editableObj).css("background","#FDFDFD");
}
});
}
</script>
我想這一點: 新組件text = text.replace(" "," ");
var _onPaste_StripFormatting_IEPaste = false;
function OnPaste_StripFormatting(elem, e) {
if (e.originalEvent && e.originalEvent.clipboardData && e.originalEvent.clipboardData.getData) {
e.preventDefault();
var text = e.originalEvent.clipboardData.getData('text/plain');
string text = text;
text = text.replace(" "," ");
window.document.execCommand('insertText', false, text);
}
else if (e.clipboardData && e.clipboardData.getData) {
e.preventDefault();
var text = e.clipboardData.getData('text/plain');
string text = text;
text = text.replace(" "," ");
window.document.execCommand('insertText', false, text);
}
else if (window.clipboardData && window.clipboardData.getData) {
// Stop stack overflow
if (!_onPaste_StripFormatting_IEPaste) {
_onPaste_StripFormatting_IEPaste = true;
e.preventDefault();
window.document.execCommand('ms-pasteTextOnly', false);
}
_onPaste_StripFormatting_IEPaste = false;
}
}
但沒有
https://jsfiddle.net/subsa/79dr2grn/未替換,甚至第一羣組。從CSS粘貼文本,有隱藏nbsp –