我知道可以string.find()用来在字符串中查找子字符串.
但是,找出其中一个数组项是否在不使用循环的情况下在字符串中具有子字符串匹配的最简单方法是什么?
伪代码:
string = 'I would like an apple.'
search = ['apple','orange', 'banana']
string.find(search) # == True
Run Code Online (Sandbox Code Playgroud) 如何在不使用get变量的情况下使用download.php?get = file.exe,例如download.php?= file.exe,在PHP中使用$ _GET?
我正在使用此代码搜索大约500 li标签.
$(function() {
$.expr[":"].containsInCaseSensitive = function(el, i, m){
var search = m[3];
if (!search) return false;
return eval("/" + search + "/i").test($(el).text());
};
$('#query').focus().keyup(function(e){
if(this.value.length > 0){
$('ul#abbreviations li').hide();
$('ul#abbreviations li:containsInCaseSensitive(' + this.value + ')').show();
} else {
$('ul#abbreviations li').show();
}
if(e.keyCode == 13) {
$(this).val('');
$('ul#abbreviations li').show();
}
});
});
Run Code Online (Sandbox Code Playgroud)
这是HTML:
<input type="text" id="query" value=""/>
<ul id="abbreviations">
<li>ABC<span>description</span></li>
<li>BCA<span>description</span></li>
<li>ADC<span>description</span></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
这个许多li标签的脚本非常慢.
如何让它更快,如何只搜索li中的ABC文本,而不是搜索span标签(不更改html)?
我知道现有的插件,但我需要一个像这样的小实现.
这是任何感兴趣的人的完成代码
var abbrs = {};
$('ul#abbreviations li').each(function(i){
abbrs[this.firstChild.nodeValue] = i;
});
$('#query').focus().keyup(function(e){
if(this.value.length >= …Run Code Online (Sandbox Code Playgroud) 我正在研究IE6的内部网项目(我知道......),我需要从div输出一些HTML代码.
我用 $('#output').text($('#container').html());
但IE6以大写形式输出所有代码:
<TABLE border=1>
<TR>
<TD>Test Content</TD>
</TR>
</TABLE>
Run Code Online (Sandbox Code Playgroud)
如何使用jQuery将HTML标记转换为小写?
有一个可以递归地通过DOM树的插件会很有用.
我正在尝试使用AVA编写测试,但我似乎无法让它工作写.fn通过我的所有函数传递回调函数,并在完成所有操作后调用它.我的考试是
import test from 'ava';
import fn from './index.js';
test('NonLiteral && Literal', function (t) {
fn('test.txt', '', function (res) {
console.log(res);
t.is(res, '');
});
});
Run Code Online (Sandbox Code Playgroud)
res是
This is a test
How is it going
So far!!!
Run Code Online (Sandbox Code Playgroud)
但它说我的测试正在通过.我一直在关注这个测试.这是我一直在关注的片段
test('throwing a named function will report the to the console', function (t) {
execCli('fixture/throw-named-function.js', function (err, stdout, stderr) {
t.ok(err);
t.match(stderr, /\[Function: fooFn]/);
// TODO(jamestalmage)
// t.ok(/1 uncaught exception[^s]/.test(stdout));
t.end();
});
});
Run Code Online (Sandbox Code Playgroud)
有人可以向我解释我做错了什么吗?
我觉得这个XML无效,有人可以解释一下原因吗?
我认为它有点东西这个点我的元素名称?
estate_price.price_suggestion
还有什么其他的东西对这个XML无效吗?
XML
\\ <?xml version="1.0" encoding="UTF-8"?>
<iad>
<DataTag>
<element id="0">
<changed_string>content</changed_string>
<no_of_bedrooms>content</no_of_bedrooms>
<published_string>content</published_string>
<mmo>content</mmo>
<postcode>content</postcode>
<utmx>content</utmx>
<utmy>content</utmy>
<disposed>content</disposed>
<property_type>content</property_type>
<isprivate>content</isprivate>
<heading>content</heading>
<published>content</published>
<estate_price.price_suggestion>content</estate_price.price_suggestion>
<ownership_type>content</ownership_type>
<estate_size.useable_area>content</estate_size.useable_area>
<adid>content</adid>
<address>content</address>
<sqmtrprice>content</sqmtrprice>
<estate_size.primary_room_area>content</estate_size.primary_room_area>
<location>content</location>
<changed>content</changed>
<orgname>content</orgname>
</element>
<element id="1">
<changed_string>content</changed_string>
<no_of_bedrooms>content</no_of_bedrooms>
<published_string>content</published_string>
<mmo>content</mmo>
<postcode>content</postcode>
<utmx>content</utmx>
<utmy>content</utmy>
<disposed>content</disposed>
<property_type>content</property_type>
<isprivate>content</isprivate>
<heading>content</heading>
<published>content</published>
<estate_price.price_suggestion>content</estate_price.price_suggestion>
<ownership_type>content</ownership_type>
<estate_size.useable_area>content</estate_size.useable_area>
<adid>content</adid>
<address>content</address>
<sqmtrprice>content</sqmtrprice>
<estate_size.primary_room_area>content</estate_size.primary_room_area>
<location>content</location>
<changed>content</changed>
<orgname>content</orgname>
</element>
</DataTag>
</iad>
Run Code Online (Sandbox Code Playgroud) 我刚刚开始在AS3编码,从专家那里得到一些反馈真的很棒; 在我的编码风格,我做错的事情,我可以改进的事情,最佳实践等等......如果你有一些额外的提示或技巧,那将是很好的.
这是我的第一个AS3代码,花了我5个小时,puh:
package {
import flash.display.Sprite;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.*;
import flash.errors.*;
import flash.display.MovieClip;
import gs.*;
import flash.display.Loader;
import net.stevensacks.preloaders.CircleSlicePreloader;
public class FlatSelector extends MovieClip {
var preloader:CircleSlicePreloader = new CircleSlicePreloader();
var imageLoader:Loader = new Loader();
var globalXML:XML;
public function FlatSelector() {
stage.addEventListener(Event.ENTER_FRAME, init);
building.alpha = 0;
}
public function init(event:Event):void {
stage.removeEventListener(Event.ENTER_FRAME, init);
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, handleXML);
loader.load(new URLRequest('http://localhost/boligvelger/flats.xml'));
TweenLite.to(building, 2, {alpha:1});
TweenLite.to(building.flat, 2, {alpha:0.5, tint:0x00FF23});
//var myTween:TweenLite = TweenLite.to(mc, 1, {x:200});
//var …Run Code Online (Sandbox Code Playgroud) 如何在普通的Javascript中编写这个jQuery代码?
我不能使用jQuery来使用它.
$(function(){
$("td#dark[height='260']").append("<a href='http://www.website.com'></a>");
});
Run Code Online (Sandbox Code Playgroud) 我需要一个javascript书签来获取我在剪贴板中的网址解析出2个数字并创建一个新网址,并添加一个链接到页面顶部,单击时将该网址添加到我的书签菜单.
说我有这样的网址
http://www.website.com/frontpageeditor.jhtml?sectionID=2844&poolID=6276
javascript:getPoolPageUrl(9800,22713)
然后我需要将数字添加到此网址
javascript:frames['content'].getPoolPageUrl(9800,22713)
然后将URL添加到框架"content"的顶部.
我已经在这方面做了很久,但我无法弄明白.
更新
我把一些东西放在一起,向你展示我需要的东西.这个不起作用.
有什么想法吗?
var url = window.clipboardData.getData('Text');
var reg = /(\d+)/g;
var matches = url.match(reg); //returns ["2844","6276"]
var newUrl = "javascript:frames['content'].getPoolPageUrl("+matches[0]+","+matches[1]+")";
var link = document.createElement('a');
link.src = newUrl;
frames['content'].document.body.appendChild(link);
Run Code Online (Sandbox Code Playgroud)
Update2
这有效.我能做些什么改变才能让它变得更好?
var url = window.clipboardData.getData('text');
var matches = url.match(/(\d+)/g);
var link = frames['content'].document.createElement('a');
link.href = "javascript:frames['content'].getPoolPageUrl("+matches[0]+","+matches[1]+")";
link.innerHTML = document.title;
frames['content'].document.body.appendChild(link);
Run Code Online (Sandbox Code Playgroud) 如何在C++中制作一个屏幕保护程序,在淡出时指定的时间延迟,在屏幕上的随机位置淡入和淡出图像?
多监视器支持非常棒.
如果您有工作代码或知道我可以在哪里获得它,那就太棒了.否则指向正确的方向.我正在寻找一种方法,它具有平滑而不滞后的og flickery fade.屏幕保护程序适用于Windows XP.
我不懂C++,但我知道AS3,Javascript和PHP.所以我希望将一些知识与C++联系起来.
我应该用什么来编译它?
我不能让这个循环执行它应该的阶乘.它似乎只是循环一次.
static void Main(string[] args)
{
int a;
int total=1;
Console.WriteLine("Please enter any number");
a = Convert.ToInt32 (Console.ReadLine());
total = a;
for (int intcount = a; intcount<= 1; intcount--)
{
total *= intcount;
}
Console.WriteLine("Factorial of number '{0}' is '{1}'", a, total);
Console.ReadKey();
Run Code Online (Sandbox Code Playgroud) javascript ×3
jquery ×3
actionscript ×2
flash ×2
html ×2
url ×2
arrays ×1
ava ×1
bookmarklet ×1
c# ×1
c++ ×1
dtd ×1
factorial ×1
fade ×1
feedback ×1
find ×1
get ×1
list ×1
lowercase ×1
match ×1
node.js ×1
optimization ×1
parsing ×1
performance ×1
php ×1
python ×1
regex ×1
schema ×1
screensaver ×1
screenshot ×1
search ×1
string ×1
testing ×1
uppercase ×1
windows ×1
windows-xp ×1
xml ×1
xsd ×1