半同步复制,Javascript复制实例详解

作者:计算机知识

mongo复制集同步验证的实例详解

Javascript复制实例详解,javascript实例详解

必赢亚州网址,在做项目时有一个急需,是急需复制内容到剪切板,因为有好些个浏览器,所以要包容性很关键。

一、最简易的copy,只幸亏IE下使用

使用clipboardData方法

<script type="text/javascript">
function copy(){
window.clipboardData.setData("text",document.getElementById("name").value);
alert("The text is on the clipboard, try to paste it!");
}
</script> 

二、跨浏览器的,可是Firefox不可能复制

<head>
<script type="text/javascript">
function CopyToClipboard () {
var input = document.getElementById ("toClipboard");
var textToClipboard = input.value;
var success = true;
if (window.clipboardData) { // Internet Explorer
window.clipboardData.setData ("Text", textToClipboard);
}
else {
// create a temporary element for the execCommand method
var forExecElement = CreateElementForExecCommand (textToClipboard);
/* Select the contents of the element 
(the execCommand for 'copy' method works on the selection) */
SelectContent (forExecElement);
var supported = true;
// UniversalXPConnect privilege is required for clipboard access in Firefox
try {
if (window.netscape && netscape.security) {
netscape.security.PrivilegeManager.enablePrivilege ("UniversalXPConnect");
}
// Copy the selected content to the clipboard
// Works in Firefox and in Safari before version 5
success = document.execCommand ("copy", false, null);
}
catch (e) {
success = false;
}
// remove the temporary element
document.body.removeChild (forExecElement);
}
if (success) {
alert ("The text is on the clipboard, try to paste it!");
}
else {
alert ("Your browser doesn't allow clipboard access!");
}
}
function CreateElementForExecCommand (textToClipboard) {
var forExecElement = document.createElement ("div");
// place outside the visible area
forExecElement.style.position = "absolute";
forExecElement.style.left = "-10000px";
forExecElement.style.top = "-10000px";
// write the necessary text into the element and append to the document
forExecElement.textContent = textToClipboard;
document.body.appendChild (forExecElement);
// the contentEditable mode is necessary for the execCommand method in Firefox
forExecElement.contentEditable = true;
return forExecElement;
}
function SelectContent (element) {
// first create a range
var rangeToSelect = document.createRange ();
rangeToSelect.selectNodeContents (element);
// select the contents
var selection = window.getSelection ();
selection.removeAllRanges ();
selection.addRange (rangeToSelect);
}
</script>
</head>
<body>
<input id="toClipboard" value="text to clipboard"/>
<button onclick='CopyToClipboard ()'>Copy text to clipboard</button>
</body>

测试后,Firefox访问退步

半同步复制,Javascript复制实例详解。3、万能的flash

并非再一次造轮子了,有三个选用大规模的类库ZeroClipboard

Zero Clipboard 的贯彻原理

Zero Clipboard 利用 Flash 举行复制,在此之前有 Clipboard Copy 化解方案,其采纳的是3个躲藏的 Flash。但新型的 Flash Player 十 只同意在Flash 上拓展操作本事运行剪贴板。所以 Zero Clipboard 对此张开了校对,用了贰个晶莹剔透的 Flash ,让其飘忽在开关之上,那样实在点击的不是开关而是 Flash ,也就足以应用 Flash 的复制成效了。

创设2个晶莹剔透的flash

将那些flash浮在开关上层

规定要复制的文书是哪些

监听这几个透明flash的鼠标点击事件

该flash被点击之后,完毕剪切板管理

对于这几件事,ZeroClipboard分别提供了不相同的api,来完毕全套须求

什么利用 Zero Clipboard

git clone

关于ZeroClipboard.js

var ZeroClipboard = {
version: "1.0.7",
clients: {},
moviePath: "zeroclipboard.swf",
nextId: 1,
$: function(A) {
if (typeof(A) == "string") {
A = document.getElementById(A)
}
if (!A.addClass) {
A.hide = function() {
this.style.display = "none"
};
A.show = function() {
this.style.display = ""
};
A.addClass = function(B) {
this.removeClass(B);
this.className  = " "   B
};
A.removeClass = function(D) {
var E = this.className.split(/s /);
var B = -1;
for (var C = 0; C < E.length; C  ) {
if (E[C] == D) {
B = C;
C = E.length
}
}
if (B > -1) {
E.splice(B, 1);
this.className = E.join(" ")
}
return this
};
A.hasClass = function(B) {
return !!this.className.match(new RegExp("\s*"   B   "\s*"))
}
}
return A
},
setMoviePath: function(A) {
this.moviePath = A
},
dispatch: function(D, B, C) {
var A = this.clients[D];
if (A) {
A.receiveEvent(B, C)
}
},
register: function(B, A) {
this.clients[B] = A
},
getDOMObjectPosition: function(C, A) {
var B = {
left: 0,
top: 0,
width: C.width ? C.width : C.offsetWidth,
height: C.height ? C.height : C.offsetHeight
};
while (C && (C != A)) {
B.left  = C.offsetLeft;
B.top  = C.offsetTop;
C = C.offsetParent
}
return B
},
Client: function(A) {
this.handlers = {};
this.id = ZeroClipboard.nextId  ;
this.movieId = "ZeroClipboardMovie_"   this.id;
ZeroClipboard.register(this.id, this);
if (A) {
this.glue(A)
}
}
};
ZeroClipboard.Client.prototype = {
id: 0,
ready: false,
movie: null,
clipText: "",
handCursorEnabled: true,
cssEffects: true,
handlers: null,
//我们可以通过下面这个api,将flash和按钮重叠,且浮在按钮之上
glue: function(D, B, E) {
this.domElement = ZeroClipboard.$(D);
var F = 99;
if (this.domElement.style.zIndex) {
F = parseInt(this.domElement.style.zIndex, 10)   1
}
if (typeof(B) == "string") {
B = ZeroClipboard.$(B)
} else {
if (typeof(B) == "undefined") {
B = document.getElementsByTagName("body")[0]
}
}
var C = ZeroClipboard.getDOMObjectPosition(this.domElement, B);
this.div = document.createElement("div");
var A = this.div.style;
A.position = "absolute";
A.left = ""   C.left   "px";
A.top = ""   C.top   "px";
A.width = ""   C.width   "px";
A.height = ""   C.height   "px";
A.zIndex = F;
if (typeof(E) == "object") {
for (addedStyle in E) {
A[addedStyle] = E[addedStyle]
}
}
B.appendChild(this.div);
this.div.innerHTML = this.getHTML(C.width, C.height)
},
/*IE 的 Flash JavaScript 通信接口上有一个 bug 。
你必须插入一个 object 标签到一个已存在的 DOM 元素中。并且在写入 innerHTML 之前请确保该元素已经 appendChild 方法插入到 DOM 中*/
getHTML: function(D, A) {
var C = "";
var B = "id="   this.id   "&width="   D   "&height="   A;
if (navigator.userAgent.match(/MSIE/)) {
var E = location.href.match(/^https/i) ? "https://" : "http://";
C  = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'   E   'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'   D   '" height="'   A   '" id="'   this.movieId   '" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'   ZeroClipboard.moviePath   '" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="'   B   '"/><param name="wmode" value="transparent"/></object>'
} else {
C  = '<embed id="'   this.movieId   '" src="'   ZeroClipboard.moviePath   '" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'   D   '" height="'   A   '" name="'   this.movieId   '" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'   B   '" wmode="transparent" />'
}
return C
},
hide: function() {
if (this.div) {
this.div.style.left = "-2000px"
}
},
show: function() {
this.reposition()
},
destroy: function() {
if (this.domElement && this.div) {
this.hide();
this.div.innerHTML = "";
var A = document.getElementsByTagName("body")[0];
try {
A.removeChild(this.div)
} catch (B) {}
this.domElement = null;
this.div = null
}
},
/* 因为按钮上漂浮有一个 Flash 按钮,所以当页面大小发生变化时,Flash 按钮可能会错位,就点不着了
Zero Clipboard 提供了一个 reposition() 方法,可以重新计算 Flash 按钮的位置。我们可以将它绑定到 resize 事件上
bind(window, "resize", function(){ clip.reposition(); }); 
function bind(obj, type, fn) {
if (obj.attachEvent) {
obj['e'   type   fn] = fn;
obj[type   fn] = function() {
obj['e'   type   fn](window.event);
}
obj.attachEvent('on'   type, obj[type   fn]);
} else
obj.addEventListener(type, fn, false);
}*/
reposition: function(C) {
if (C) {
this.domElement = ZeroClipboard.$(C);
if (!this.domElement) {
this.hide()
}
}
if (this.domElement && this.div) {
var B = ZeroClipboard.getDOMObjectPosition(this.domElement);
var A = this.div.style;
A.left = ""   B.left   "px";
A.top = ""   B.top   "px"
}
},
setText: function(A) {
this.clipText = A;
if (this.ready) {
this.movie.setText(A)
}
},
addEventListener: function(A, B) {
A = A.toString().toLowerCase().replace(/^on/, "");
if (!this.handlers[A]) {
this.handlers[A] = []
}
this.handlers[A].push(B)
},
setHandCursor: function(A) {
this.handCursorEnabled = A;
if (this.ready) {
this.movie.setHandCursor(A)
}
},
/*鼠标移到按钮上或点击时,由于有 Flash 按钮的遮挡,所以像 css ":hover", ":active" 等伪类可能会失效。
setCSSEffects() 方法就是解决这个问题。首先我们需要将伪类改成类
copy - botton: hover {
border - color: #FF6633;
}

能够改成下边包车型客车 ":hover" 改成 ".hover"

copy - botton.hover {
border - color: #FF6633;
}

大家得以调用 clip.setCSSEffects( true ); 那样 Zero Clipboard 会自动为咱们管理:将类 .hover 当成伪类 :hover*/

setCSSEffects: function(A) {
this.cssEffects = !! A
},
/*Zero Clipboard 提供了一些事件,你可以自定义函数处理这些事件。
Zero Clipboard 事件处理函数为 addEventListener(); 例如当 Flash 完全载入后会触发一个事件 "load" 
clip.addEventListener( "load", function(client) { 
alert("Flash 加载完毕!"); 
});*/
receiveEvent: function(D, E) {
D = D.toString().toLowerCase().replace(/^on/, "");
switch (D) {
case "load":
this.movie = document.getElementById(this.movieId);
if (!this.movie) {
var C = this;
setTimeout(function() {
C.receiveEvent("load", null)
}, 1);
return
}
if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(/Windows/)) {
var C = this;
setTimeout(function() {
C.receiveEvent("load", null)
}, 100);
this.ready = true;
return
}
this.ready = true;
this.movie.setText(this.clipText);
this.movie.setHandCursor(this.handCursorEnabled);
break;
case "mouseover":
if (this.domElement && this.cssEffects) {
this.domElement.addClass("hover");
if (this.recoverActive) {
this.domElement.addClass("active")
}
}
break;
case "mouseout":
if (this.domElement && this.cssEffects) {
this.recoverActive = false;
if (this.domElement.hasClass("active")) {
this.domElement.removeClass("active");
this.recoverActive = true
}
this.domElement.removeClass("hover")
}
break;
case "mousedown":
if (this.domElement && this.cssEffects) {
this.domElement.addClass("active")
}
break;
case "mouseup":
if (this.domElement && this.cssEffects) {
this.domElement.removeClass("active");
this.recoverActive = false
}
break
}
if (this.handlers[D]) {
for (var B = 0, A = this.handlers[D].length; B < A; B  ) {
var F = this.handlers[D][B];
if (typeof(F) == "function") {
F(this, E)
} else {
if ((typeof(F) == "object") && (F.length == 2)) {
F[0][F[1]](this, E)
} else {
if (typeof(F) == "string") {
window[F](this, E)
}
}
}
}
}
}
}; 

以上所述是小编给我们介绍的Javascript复制实例详解,希望对我们有着帮衬。

在做项目时有贰个供给,是索要复制内容到剪切板,因为有繁多浏览器,所以要包容性很重点。

转载自:https://www.cnblogs.com/ivictor/p/5735580.html

第一步:在主节点上插入一条数据

您或者感兴趣的篇章:

  • 采取js完毕节点的增加和删除改复制等的操作
  • JS将制定内容复制到剪切板示例代码
  • 网址内容不准复制和粘贴、另存为的js代码
  • 用js将内容复制到剪贴板包容浏览器
  • 合营所有浏览器的js复制插件Zero使用介绍
  • js完毕的复制包容chrome和IE
  • 在Node.js中落到实处文件复制的法门和实例
  • 深远研究JavaScript、JQuery屏蔽网页鼠标右键菜单及禁止选择复制
  • Javascript 完成复制(Copy)动作方法大全
  • js完结点击后将文字或图片复制到剪贴板的主意
  • 原生js完成复制对象、扩大对象 类似jquery中的extend()方法
  • 相称主流浏览器的JS复制内容到剪贴板

在做项目时有三个必要,是急需复制内容到剪切板,因为有无数浏览器,所以要包容性很主要。...

一、最简便的copy,只还好IE下使用

  • 异步复制(Asynchronous replication)

Sql代码 

使用clipboardData方法

MySQL暗中同意的复制正是异步的,主库在实践完客户端提交的事体后会马上将结果返给给客户端,并不敬听从库是不是早已接收并管理,那样就能够有2个标题,主假设crash掉了,此时主故洗经付出的业务大概并从未传来从上,如若此时,强行将从进步为主,也许引致新主上的多少不完全。

rs0:PRIMARY> use imooc 
switched to db imooc 
rs0:PRIMARY> db.imooc.insert({"name":"imooc"}) 
WriteResult({ "nInserted" : 1 }) 
<script type="text/javascript">
function copy(){
window.clipboardData.setData("text",document.getElementById("name").value);
alert("The text is on the clipboard, try to paste it!");
}
</script> 
  • 全同台复制(Fully synchronous replication)

其次步:在从节点查看数据,看是或不是同步

二、跨浏览器的,不过Firefox不能够复制

指当主库实践完贰个业务,全数的从库都实践了该业务才回来给客户端。因为需求静观其变全数从库实践完该事务技能回到,所以全同步复制的特性必然会吸取严重的影响。

Sql代码 

<head>
<script type="text/javascript">
function CopyToClipboard () {
var input = document.getElementById ("toClipboard");
var textToClipboard = input.value;
var success = true;
if (window.clipboardData) { // Internet Explorer
window.clipboardData.setData ("Text", textToClipboard);
}
else {
// create a temporary element for the execCommand method
var forExecElement = CreateElementForExecCommand (textToClipboard);
/* Select the contents of the element 
(the execCommand for 'copy' method works on the selection) */
SelectContent (forExecElement);
var supported = true;
// UniversalXPConnect privilege is required for clipboard access in Firefox
try {
if (window.netscape && netscape.security) {
netscape.security.PrivilegeManager.enablePrivilege ("UniversalXPConnect");
}
// Copy the selected content to the clipboard
// Works in Firefox and in Safari before version 5
success = document.execCommand ("copy", false, null);
}
catch (e) {
success = false;
}
// remove the temporary element
document.body.removeChild (forExecElement);
}
if (success) {
alert ("The text is on the clipboard, try to paste it!");
}
else {
alert ("Your browser doesn't allow clipboard access!");
}
}
function CreateElementForExecCommand (textToClipboard) {
var forExecElement = document.createElement ("div");
// place outside the visible area
forExecElement.style.position = "absolute";
forExecElement.style.left = "-10000px";
forExecElement.style.top = "-10000px";
// write the necessary text into the element and append to the document
forExecElement.textContent = textToClipboard;
document.body.appendChild (forExecElement);
// the contentEditable mode is necessary for the execCommand method in Firefox
forExecElement.contentEditable = true;
return forExecElement;
}
function SelectContent (element) {
// first create a range
var rangeToSelect = document.createRange ();
rangeToSelect.selectNodeContents (element);
// select the contents
var selection = window.getSelection ();
selection.removeAllRanges ();
selection.addRange (rangeToSelect);
}
</script>
</head>
<body>
<input id="toClipboard" value="text to clipboard"/>
<button onclick='CopyToClipboard ()'>Copy text to clipboard</button>
</body>
  • 半联袂复制(Semisynchronous replication)
rs0:SECONDARY> use imooc 
switched to db imooc 
rs0:SECONDARY> show tables 
2017-06-14T19:33:06.118 0800 E QUERY  [thread1] Error: listCollections failed: { "ok" : 0, "errmsg" : "not master and slaveOk=false", "code" : 13435 } : 
_getErrorWithCode@src/mongo/shell/utils.js:25:13 
DB.prototype._getCollectionInfosCommand@src/mongo/shell/db.js:773:1 
DB.prototype.getCollectionInfos@src/mongo/shell/db.js:785:19 
DB.prototype.getCollectionNames@src/mongo/shell/db.js:796:16 
shellHelper.show@src/mongo/shell/utils.js:754:9 
shellHelper@src/mongo/shell/utils.js:651:15 
@(shellhelp2):1:1 
rs0:SECONDARY> rs.slaveOk() 
rs0:SECONDARY> show tables 
imooc 
rs0:SECONDARY> db.imooc.find() 
{ "_id" : ObjectId("59411e1c925a4f4db145e9af"), "name" : "imooc" } 
rs0:SECONDARY> 

测试后,Firefox访问战败

在于异步复制和全同台复制之间,主库在举行完客户端提交的事体后不是即时回到给客户端,而是等待至少1个从库接收到并写到relay log中才再次来到给客户端。相对于异步复制,半联合举办理并答复制升高了数量的安全性,同偶尔候它也招致了自然水平的延期,那几个延迟最少是二个TCP/IP往返的时刻。所以,半一块复制最佳在低延时的互连网中使用。

本文由bwin必赢发布,转载请注明来源

关键词: 亚洲必赢766net MySQL