程序设计

专业和发烧友程序员的问答

9
Javascript切换与if ... else if ... else
伙计们,我有几个问题: switch语句和an 之间在JavaScript中是否存在性能差异if...else? 如果可以,为什么? 是的行为switch和if...else跨浏览器的不同?(FireFox,IE,Chrome,Opera,Safari) 提出这个问题的原因是,switch在Firefox中大约有1000多个案例的情况下,我似乎获得了更好的性能。 编辑 Unfortuantly这不是我的代码JavaScript是正在生产服务器端从编译的库,我要的代码的访问权限。产生javascript的方法称为 CreateConditionals(string name, string arrayofvalues, string arrayofActions) note arrayofvalues是用逗号分隔的列表。 它产生的是 function [name] (value) { if (value == [value from array index x]) { [action from array index x] } } 注意:其中[name]=传递给服务器端函数的名称 现在,我更改了要插入TextArea的函数的输出,编写了一些JavaScript代码以解析该函数​​,然后将其转换为一组case语句。 最后,我运行了该函数,并且运行良好,但是在IE和Firefox中性能有所不同。

4
CSS:如何将position:absolute div放在一个position:relative div内,而不会被溢出:隐藏在容器中
我有3个级别div: (下面的绿色)div带有的顶层overflow: hidden。这是因为我希望如果该框内的某些内容(此处未显示)超出框的大小,则会对其进行裁剪。 (在下面红色)这里面,我也div有position: relative。唯一的用途是用于下一个级别。 (下面的蓝色)最后,div我从流程中取出,position: absolute但要相对于红色div(而不是页面)进行定位。 我希望将蓝色框从流程中移出并扩展到绿色框之外,但要相对于红色框定位,如下所示: 但是,使用下面的代码,我得到: 并移除position: relative红色框上的,现在允许蓝色框脱离绿色框,但不再相对于红色框定位: 有没有办法: 将保持overflow: hidden在绿色框上。 蓝色框是否已超出绿色框并相对于红色框定位? 完整资料: #d1 { overflow: hidden; background: #efe; padding: 5px; width: 125px; } #d2 { position: relative; background: #fee; padding: 2px; width: 100px; height: 100px; } #d3 { position: absolute; top: 10px; background: #eef; padding: 2px; …

11
随机“元素不再附加到DOM” StaleElementReferenceException
我希望只是我一个人,但是Selenium Webdriver似乎是一场噩梦。Chrome网络驱动程序当前无法使用,而其他驱动程序则非常不可靠,似乎如此。我正在与许多问题作斗争,但这是一个。 随机地,我的测试会因 "org.openqa.selenium.StaleElementReferenceException: Element is no longer attached to the DOM System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_23'" 我正在使用2.0b3版的网络驱动程序。我已经看到FF和IE驱动程序会发生这种情况。我可以防止这种情况的唯一方法是Thread.sleep在发生异常之前添加一个实际的调用。但是,这是一个很差的解决方法,所以我希望有人指出我的错误,这将使一切变得更好。

9
Emacs中是否有(repeat-last-command)?
通常,我会深入研究apropos和docs,寻找类似以下内容的内容,只是为了放弃手头的任务而放弃: (repeat-last-command) 执行我刚刚执行的最后一个C-或M-命令(将其反弹到fn键) 或有时相关: (描述最后一个功能) 我只是错误地发出了什么按键,我想将其效果添加到我的技巧包中。describe-key很接近,但是需要知道我输入的内容。 我只是向我可信赖的伙伴问了太多吗?
143 emacs  elisp 



17
无法通过套接字'/tmp/mysql.sock'(2)连接到本地MySQL服务器
我已经安装了MySQL服务器并尝试连接到它,但是出现错误: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 我已经检查了我的/ tmp目录,并且没有mysql.sock。我在任何地方都找不到mysql.sock。我读到它可能在 /var/lib/mysql/mysql.sock 但是我也检查了那里,甚至没有mysql目录,在/ lib中只有一些后缀。有人可以帮我解决这个问题吗?
143 mysql  sql 

4
CENTER_INSIDE和FIT_CENTER比例类型有什么区别?
我不能告诉之间的区别ImageView.ScaleType.CENTER_INSIDE和ImageView.ScaleType.FIT_CENTER。 CENTER_INSIDE 统一缩放图像(保持图像的纵横比),以使图像的两个尺寸(宽度和高度)都等于或小于视图的相应尺寸(减去填充)。 FIT_CENTER 计算一个比例,该比例将保持原始的src纵横比,但也将确保src完全适合dst。至少一个轴(X或Y)将完全适合。结果位于dst内部。 有人可以阐明两者之间的区别吗?


7
为什么UICollectionViewCell的出口为零?
我在Interface Builder中创建了一个自定义UICollectionViewCell,将其上的视图绑定到该类,然后当我要使用字符串并将其设置为字符串上的标签时,tha标签的值为nil。 override func viewDidLoad() { super.viewDidLoad() // Register cell classes self.collectionView.registerClass(LeftMenuCollectionViewCell.self, forCellWithReuseIdentifier: "ls") } override func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell! { var cell: LeftMenuCollectionViewCell cell = collectionView.dequeueReusableCellWithReuseIdentifier("ls", forIndexPath: indexPath) as LeftMenuCollectionViewCell println(cell.label) // <- this is nil, why?? cell.label.text = "asd" return cell } 和子类的单元格: class …

6
在每个列表项之后插入图像
在每个列表元素之后插入小图像的最佳方法是什么?我尝试了一个伪类,但是有些不对劲... ul li a:after {display: block; width: 3px; height: 5px; background: url ('../images/small_triangle.png') transparent no-repeat;} 谢谢你的帮助!
143 css 

8
Rails:致命-用户的对等身份验证失败(PG :: Error)
我正在Ubuntu 11.10和RubyMine上运行开发 这是我对database.yml的开发设置:RubyMine为我创建的 development: adapter: postgresql encoding: unicode database: mydb_development pool: 5 username: myuser password: 当我尝试运行该应用程序时,出现以下错误,似乎我还没有创建“项目”用户,但是,如何在postgres中创建用户并为其授予数据库?如果这是问题所在,那么在Ubuntu中为此任务推荐使用什么工具?如果这不是问题,那么请提出建议。 Exiting /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:1194:in `initialize': FATAL: Peer authentication failed for user "project" (PG::Error) from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:1194:in `new' from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:1194:in `connect' from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:329:in `initialize' from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new' from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection' from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:303:in `new_connection' from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:313:in `checkout_new_connection' from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:237:in …

11
使html svg对象也成为可点击的链接
我的HTML页面中有一个SVG对象,并将其包装在锚点中,因此,当单击svg图像时,会将用户带到锚点链接。 <a href="http://www.google.com/"> <object data="mysvg.svg" type="image/svg+xml"> <span>Your browser doesn't support SVG images</span> </object> </a> 当我使用此代码块时,单击svg对象不会将我带到Google。在IE8 <中,跨度文本是可单击的。 我不想修改我的svg图像以包含标签。 我的问题是,如何使svg图像可点击?
143 html  object  svg  anchor 

14
为什么require_once不好用?
我所读到的有关更好的PHP编码实践的所有内容一直在说不要require_once因为速度而使用。 为什么是这样? 做相同的事情的正确/更好的方法是什么require_once?如果有关系,我正在使用PHP 5。


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.