我正在尝试使用jQuery向现有的CKEditor添加一段文本.这需要在单击链接时完成.
我试过这个解决方案,适用于常规textareas,但不适用于CKEditor:
jQuery.fn.extend({
insertAtCaret: function(myValue) {
return this.each(function(i) {
if (document.selection) {
//For browsers like Internet Explorer
this.focus();
sel = document.selection.createRange();
sel.text = myValue;
this.focus();
} else if (this.selectionStart || this.selectionStart == '0') {
//For browsers like Firefox and Webkit based
var startPos = this.selectionStart;
var endPos = this.selectionEnd;
var scrollTop = this.scrollTop;
this.value = this.value.substring(0, startPos) + myValue + this.value.substring(endPos, this.value.length);
this.focus();
this.selectionStart = startPos + myValue.length;
this.selectionEnd = startPos + myValue.length;
this.scrollTop = scrollTop;
} else {
this.value …Run Code Online (Sandbox Code Playgroud) 在过去的几天里,我发现了一些奇怪的优化我的查询.我有一个简单的查询,它具有以下特点:
SELECT id,name,amount FROM reservations WHERE NOT canceled ORDER BY name ASC
Run Code Online (Sandbox Code Playgroud)
我注意到mysql没有使用任何索引,所以我开始做一些实验.无意中我将"NOT cancel"替换为"cancelled = false",然后,Mysql开始使用"cancelled"作为索引.之后我尝试使用相反的方法:
SELECT ... FROM reservations WHERE canceled ORDER BY ...
Run Code Online (Sandbox Code Playgroud)
结果相同!当我将其更改为"cancelled = true"时,索引再次起作用.
我的问题是:怎么样?!是不是使用"NOT"的"优雅"方式?无论如何,我没想到它会有任何不同.
我使用InnoDB作为引擎,但我使用MyISAM获得相同的结果.有人能澄清一切吗?谢谢.
编辑:表结构
CREATE TABLE `reservations` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`trip_code` varchar(10) DEFAULT NULL,
`departure_date` date DEFAULT NULL,
`amount` float DEFAULT NULL,
`name` varchar(45) DEFAULT NULL,
`canceled` tinyint(1) NOT NULL DEFAULT '0',
`created_date` date NOT NULL,
`creator_user` int(11) NOT NULL DEFAULT '1',
`last_update_user` int(11) NOT NULL DEFAULT '1', …Run Code Online (Sandbox Code Playgroud) 我做了一个扩展,其目的是重定向网址.即:www.google.com成为:www.mysite.com/?url=www.google.com
我发现了这篇文章: 如何通过扩展修改chrome中的当前url位置
我遇到的问题是url都被处理了.该标签最初会加载google.com,并且只有在完成后才会显示我的请求(www.mysite.com/?url=www.google.com).有没有办法阻止初始请求被处理?
就像是:
chrome.tabs.onUpdated.addListener(function(tabId,obj,tab){
update.stop() // ??????????? Here I'm missing...
chrome.tabs.update(tabId,{url:....}, function callback); // My update stuff..
});
Run Code Online (Sandbox Code Playgroud)
思考?
谢谢你们.
我有一个带有cmd键的Apple键盘,我正在尝试与控制键交换.
从谷歌问题和搜索论坛我带来了几个解决方案.不幸的是,他们都没有为我工作.我尝试过使用标准的"键盘布局",Xmodmap以及我遇到的任何内容.我得到的最接近的是交换它们但禁用箭头键.
我正在使用ubuntu 11.
希望可以有人帮帮我.先感谢您.
编辑:
这是我的xmodmap结果:
shift Shift_L (0x32), Shift_R (0x3e)
lock Caps_Lock (0x42)
control Control_L (0x25), Control_R (0x69)
mod1 Alt_L (0x40), Alt_R (0x6c), Meta_L (0xcd)
mod2 Num_Lock (0x4d)
mod3
mod4 Super_L (0x85), Super_R (0x86), Super_L (0xce), Hyper_L (0xcf)
mod5 ISO_Level3_Shift (0x5c), Mode_switch (0xcb)
Run Code Online (Sandbox Code Playgroud)
我希望控件是mod4,反之亦然.谢谢..
突然被一个问题击中时,我正在制作一个循环.这应该是"正确的方式":
// code..
$('tr','#my_table').each(function(){
$(this).click(function(){
var show_id = $(this).attr('data-show-id');
// code..
// code..
});
});
// code..
Run Code Online (Sandbox Code Playgroud)
要么
// code..
var show_id = 0; /* HERE */
$('tr','#my_table').each(function(){
$(this).click(function(){
show_id = $(this).attr('data-show-id');
// code..
// code..
});
});
Run Code Online (Sandbox Code Playgroud)
在第一个例子中,我为每个创建tr一个新变量show_id.在第二部分中,我对表中的show_id所有部分使用相同的全局,tr并在每个tr上重新填充它.
因此问题应该是:无论编程语言如何 - 在每个循环上创建一个新变量是更好的做法,当函数退出或"捕获"整个运行的内存并避免每次重新创建变量时,该变量将被释放?