我正在尝试转换JavaScript中以字节为单位表示的文件大小,如下所示(HTML 5).
function formatBytes(bytes)
{
var sizes = ['Bytes', 'kB', 'MB', 'GB', 'TB'];
if (bytes == 0)
{
return 'n/a';
}
var i = parseInt(Math.log(bytes) / Math.log(1024));
return Math.round(bytes / Math.pow(1024, i), 2) + sizes[i];
}
Run Code Online (Sandbox Code Playgroud)
但我需要以SI和二进制为单位表示文件大小,如果需要,
kB<--->KiB
MB<--->MiB
GB<--->GiB
TB<--->TiB
EB<--->EiB
Run Code Online (Sandbox Code Playgroud)
这可以在Java中完成,如下所示(对方法使用一个额外的布尔参数).
public static String formatBytes(long size, boolean si)
{
final int unitValue = si ? 1000 : 1024;
if (size < unitValue)
{
return size + " B";
}
int exp = (int) (Math.log(size) / Math.log(unitValue));
String initLetter …Run Code Online (Sandbox Code Playgroud) $(this)与缓存选择器相同吗?$(this)每次都会搜索DOM吗?
例如:
$('#selector').on('click', function() {
$(this).method();
$(this).method1();
$(this).method2();
//OR
var selector = $('#selector');
selector.method();
selector.method1();
selector.method2();
}
Run Code Online (Sandbox Code Playgroud) 这曾经工作得很好,但是最近渐变在Webkit中无法正常工作.似乎在Firefox中没问题.有人可以检查我是否设置错误.不要注意图像.它是我无法渲染的渐变.有什么想法吗?
JSFIDDLE:http://jsfiddle.net/UdxUg/2/
-webkit-gradient
Run Code Online (Sandbox Code Playgroud) 我有2个值
var maxValues;
var incrementValues;
Run Code Online (Sandbox Code Playgroud)
我有一个功能.
runFunction();
Run Code Online (Sandbox Code Playgroud)
值基于ajax成功而增加.
如何检查maxValues是否等于incrementValues,一旦它们相等,那么运行runFunction().
在角度路由中,您可以将url参数解析为$ routeParams.但是,我需要知道什么是查看它们是否存在的最佳方式.
例如,我有几个$routeParams来自URL的不同部分,但是,我想知道的是是否存在任何url参数(如果?存在和参数之后).我明白了,我可以只搜索一下?但是想知道角度内是否存在某种方式.
这是我的代码:
$routeProvider.when('/sports/:sport_id/:args?',
Run Code Online (Sandbox Code Playgroud)
sport_id和所有的args将合并在$ routeParams中.但是我只是想知道args是否存在.(查询参数)
如何在以下字符串中抓取"california"部分?
http://states.com/_states/united_states/50/california
Run Code Online (Sandbox Code Playgroud)
我正在尝试以下但不知道如何匹配最后/.
match = re.search(r'\/(.*)$', state_url)
Run Code Online (Sandbox Code Playgroud) 如何让最后一行工作?
function Animal(name){
this.name = name;
}
Animal.prototype.speak = function(){
alert('Hi, I\'m ' + this.name);
}
function Dog(name){
this.name = name;
}
Dog.prototype.bark = function(){
alert('Woof!');
};
var fido = new Dog('Fido');
fido.bark(); // Woof!
fido.speak(); // Hi, I'm Fido *can't get this to work*
Run Code Online (Sandbox Code Playgroud) 我可以这样调用这个闭包:
var increment = (function () {
var test = 0;
return function () {
test++;
console.log(test);
}
})();
increment(); //1
increment(); //2
Run Code Online (Sandbox Code Playgroud)
但是,如何使用常规函数语法调用它?
function increment() {
var test = 0;
return function () {
test++;
console.log(test);
}
}
increment()(); 1
increment()(); 1
Run Code Online (Sandbox Code Playgroud) 我想我忽略了一些东西,但是有人能看出我做错了什么吗?为什么返回2030774160?
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseData //1
options:kNilOptions
error:&error];
NSDictionary* observation = [json objectForKey:@"observation"];
NSDictionary* imperial = [observation objectForKey:@"imperial"];
NSLog(@"value of a is : %@ !\n", [imperial objectForKey:@"temp"]);
self.forecastText.text =[observation objectForKey:@"phrase_22char"];
self.hi = [imperial objectForKey:@"temp_max_24hour"];
self.forecastHigh.text =[NSString stringWithFormat:@"%d", self.hi];
NSLog(@"value of a is : %@ !\n", self.hi);
NSLog(@"value of a is : %@ !\n", self.forecastHigh.text);
Run Code Online (Sandbox Code Playgroud)
2019-01-06 11:20:15.246 TiP_Clock[2205:63494] ssssy.
2019-01-06 11:20:15.465 TiP_Clock[2205:63535] Data has loaded successfully.
2019-01-06 11:20:15.466 TiP_Clock[2205:63494] value of a is : 51 !
2019-01-06 11:20:15.466 TiP_Clock[2205:63494] value …Run Code Online (Sandbox Code Playgroud) 我目前需要使用 javascript 继续循环遍历数组。下面是我能想到的一种方法,但 1-它不起作用,2-想知道它们是否是实现这一目标的更优化或更紧凑的方法?
var myArray=[1,2,3,4]
for (var i=0; i<myArray.length; i++)
{
console.log(i + 'hi')
if (i==3)
{
i=0;
}
}
Run Code Online (Sandbox Code Playgroud) 将JavaScript属性值数组转换为int的最简洁方法是什么?(希望所有a属性都是int)
var myArray = [
{
a: "12",
b: "hits"
},
{
a: "16",
b: "hits"
}
]
Run Code Online (Sandbox Code Playgroud) javascript ×7
arrays ×2
angularjs ×1
closures ×1
css ×1
inheritance ×1
jquery ×1
objective-c ×1
python ×1
regex ×1
setinterval ×1
webkit ×1