我有一个Web应用程序,在其他窗口/选项卡中启动URL.我想检查窗口/标签是否存在; 如果没有,我想创建它,否则我想在第一个位置选择它.我用:
wf=window.open(address, web_form_target, 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=640,height=450');
if(wf!=null)
wf.focus();
Run Code Online (Sandbox Code Playgroud)
但它只是第一次(在IE中,而不是在Firefox中); 如果我在窗口中创建一个新选项卡,当我调用window.open()时没有任何反应; 如果我关闭窗口,它会重新创建它,但保持图标化...有没有办法可以遵循以获得良好的结果?
在此先感谢问候,c.
我有一个单词我需要通过正则表达式操作进行查找和替换,有时这个数组可能长达数千字.我已经测试过并发现使用公共前缀来阻止单词比单独搜索它们要快得多.也就是说,^where|why$慢于^wh(ere|y)$.显然,在这样一个简短的例子中,这并不是一个明显的区别,但是如果有数以千计的替代品并且主题字符串很长,它会快得多.
所以我正在寻找一种方法来自动执行此操作,例如将其转换string[] { "what", "why", "where", "when", "which" }为wh(at|y|e(re|n)|i(ch))
是否已经有一个公认的算法可以做到这一点?如果没有,你会怎么做?它似乎需要递归完成,但我不能完全理解如何做到这一点.我有一个我写的方法在有限的范围内工作,但它不够优雅,60行长,并使用多个嵌套的foreach循环,所以这是一个未来的维护噩梦.我相信有更好的方法,如果有人能指出我正确的方向,我会非常感激......
Suppose I have the following arrays:
List<int[]> numbers = new List<int[]>();
numbers.Add(new int[] { 1, 2, 3 });
numbers.Add(new int[] { 3, 4, 5 });
numbers.Add(new int[] { 5, 6, 7 });
int[] numbersToFind = new int[] { 4, 5, 6 };
Run Code Online (Sandbox Code Playgroud)
I want to find which of the numbers elements contains one/more of the values in numbersToFind, is there an easy way of doing this with LINQ? That is, some code that would return a IEnumerable<int[]> containing an …
List<T>有 .Count属性,而不是T<>数组.Length.我认为这是因为数组是固定长度而其他数组不是,但语法上的差异仍然令人沮丧.
如果你从一个数组重构列出,因此它提供了"不包含定义.长度"的错误,似乎具有浪费时间去改变它时.Count,并.Length在本质上是相同的.
有没有一个好方法来处理这个?是否可以扩展List<T>以添加例如.Length别名的属性,.Count反之亦然?无论出于何种原因,这都是一个坏主意吗?
我正在使用jQuery热键插件将一些按键绑定到事件.我试图改变它来绑定数组上的循环,但它不起作用.
var letters = ["a","b","c"];
for (var x in letters)
{
var letter = letters[x];
$("el").bind('keydown', letter, function() { /*...*/ })
.bind('keyup', letter, function() { /*...*/ });
}
Run Code Online (Sandbox Code Playgroud)
此代码将所有事件绑定到数组中的最后一个字母("c"),而将其他任何事件绑定到其他字母.有没有更好的方法呢?非常感谢.
无论如何我可以使这个数据库代码更短吗?它工作正常,但似乎非常冗长和重复.我想在一种方法中包装它的一些方法会更好,但是还有其他改进可以缩短它吗?
using (IDbConnection theConn = GetDatabaseConnection())
using (IDbCommand theCmd = theConn.CreateCommand())
{
theCmd.CommandText = @"INSERT INTO table(one, two, three,four)
VALUES (@one,@two,@three,@four)";
var parameterOne = theCmd.CreateParameter();
parameterOne.ParameterName = "@one";
parameterOne.Value = "text";
theCmd.Parameters.Add(parameterOne);
var parameterTwo = theCmd.CreateParameter();
parameterTwo.ParameterName = "@two";
parameterTwo.Value = "text";
theCmd.Parameters.Add(parameterTwo);
var parameterThree = theCmd.CreateParameter();
parameterThree.ParameterName = "@three";
parameterThree.Value = "text";
theCmd.Parameters.Add(parameterThree);
var parameterFour = theCmd.CreateParameter();
parameterFour.ParameterName = "@four";
parameterFour.Value = "text";
theCmd.Parameters.Add(parameterFour);
theCmd.ExecuteNonQuery();
}
Run Code Online (Sandbox Code Playgroud) 我有以下jQuery事件监听器来获取在文本框中按下的键:
$("#theInput").keyup(function (e) {
var charCode = e.keyCode || e.which;
alert(charCode);
/* rest of the code */
});
Run Code Online (Sandbox Code Playgroud)
我的问题是如何准确地获取键入的字母的代码.例如,如果我按下'a'键,它将提醒'65' - 无论是"a"还是"A".如果我将输入语言切换为外语(例如日语,中文,泰语)并按"a"键,它仍会返回"65"而不是代码,以便让我知道外来字符.
有没有办法解决这个问题,所以它给出了正确的语言和字母大小写?
javascript unicode jquery javascript-events character-encoding
我一直在寻找无法找到这个..
我有一个字符串,我想用第一个单词替换整个字符串.
例如:
字符串:"你好世界"
新字符串:"你好"
提前致谢!
假设我有两个类,Customer和Order,其中一个Customer可以有一个或多个Orders Orders.
class Customer
{
Order[] Orders;
}
class Order
{
int OrderId;
}
Run Code Online (Sandbox Code Playgroud)
如果对于任何给定的客户,我想找到所有相关的OrderId,是否有一种简单的方法可以使用linq做到这一点?与以下foreach解决方案产生相同结果的东西:
List<int> allOrderIds = new List<int>();
foreach (Order thisOrder in thisCustomer)
{
allOrderIds.Add(thisOrder.OrderId);
}
Run Code Online (Sandbox Code Playgroud)
TIA.