我想使用JavaScript(可以使用jQuery)进行一些客户端验证来检查字符串是否与正则表达式匹配:
^([a-z0-9]{5,})$
Run Code Online (Sandbox Code Playgroud)
理想情况下,它将是一个返回true或false的表达式.
我是一个JavaScript新手,确实match()做我需要的东西?它似乎检查字符串的一部分是否匹配正则表达式,而不是整个事物.
我希望将JavaScript对象的键作为数组,在jQuery或纯JavaScript中.
有没有比这更简洁的方式?
var foo = { 'alpha' : 'puffin', 'beta' : 'beagle' };
var keys = [];
for (var key in foo) {
keys.push(key);
}
Run Code Online (Sandbox Code Playgroud) 我在使用JavaScript.我想存储一个唯一的,无序的字符串值列表,其中包含以下属性:
我真正想要的是一套.有关在JavaScript中模拟集合的最佳方法的任何建议吗?
这个问题建议使用一个Object,键存储属性,并且值都设置为true:这是一种明智的方法吗?
死简单.
我该如何重命名
05_h.png
06_h.png
Run Code Online (Sandbox Code Playgroud)
至
05_half.png
06_half.png
Run Code Online (Sandbox Code Playgroud)
至少,我认为这很简单,但除非你已经知道,谷歌很难做到这一点.
谢谢....
我正在将数据发布到外部API(使用PHP,如果它是相关的).
我应该对我传递的POST变量进行URL编码吗?
或者我只需要对GET数据进行URL编码?
谢谢!
更新:这是我的PHP,如果它是相关的:
$fields = array(
'mediaupload'=>$file_field,
'username'=>urlencode($_POST["username"]),
'password'=>urlencode($_POST["password"]),
'latitude'=>urlencode($_POST["latitude"]),
'longitude'=>urlencode($_POST["longitude"]),
'datetime'=>urlencode($_POST["datetime"]),
'category'=>urlencode($_POST["category"]),
'metacategory'=>urlencode($_POST["metacategory"]),
'caption'=>($_POST["description"])
);
$fields_string = http_build_query($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
Run Code Online (Sandbox Code Playgroud) 我正在阅读D3.js文档,并且发现很难从文档中理解该selection.data方法.
这是文档中给出的示例代码:
var matrix = [
[11975, 5871, 8916, 2868],
[ 1951, 10048, 2060, 6171],
[ 8010, 16145, 8090, 8045],
[ 1013, 990, 940, 6907]
];
var tr = d3.select("body").append("table").selectAll("tr")
.data(matrix)
.enter().append("tr");
var td = tr.selectAll("td")
.data(function(d) { return d; })
.enter().append("td")
.text(function(d) { return d; });
Run Code Online (Sandbox Code Playgroud)
我理解大部分内容,但声明.data(function(d) { return d; })部分的内容是var td什么?
我最好的猜测如下:
var tr语句已将四元素数组绑定到每个tr节点var td语句然后使用该四元件阵列作为其数据,以某种方式但.data(function(d) { return d; })实际上如何获得这些数据,以及它返回了什么?
我想取字符串0.71331, 52.25378并返回0.71331,52.25378- 即只需查找数字,逗号,空格和数字,并删除空格.
这是我目前的代码:
coords = '0.71331, 52.25378'
coord_re = re.sub("(\d), (\d)", "\1,\2", coords)
print coord_re
Run Code Online (Sandbox Code Playgroud)
但这给了我0.7133,2.25378.我究竟做错了什么?
我正在尝试在我的网站上添加一个Google Plus按钮,并继续获取JavaScript安全警告,尽管我在Chrome上使用了Google推荐的代码.
我已经使用Google网站管理员推荐的代码直接复制了代码,但没有其他任何补充:
<html itemscope itemtype="http://schema.org/">
<head>
<meta itemprop="name" content="Title">
<meta itemprop="description" content="Description">
</head>
<body>
<g:plusone annotation="inline"></g:plusone>
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')\[0\]; s.parentNode.insertBefore(po, s);
})();
</script>
</body>
Run Code Online (Sandbox Code Playgroud)
在Chrome中加载此项(Mac上为15),开发者控制台会发出警告:
Unsafe JavaScript attempt to access frame with URL http://mydomain.com/
from frame with URL https://plusone.google.com/_/+1/fastbutton?url=http%3A%2F%2Fmydomain.com%2F&size=standard&count=true&annotation=inline&hl=en-US&jsh=m%3B%2F_%2Fapps-static%2F_%2Fjs%2Fwidget%2F__features__%2Frt%3Dj%2Fver%3Dt6mt7PFQYRQ.en_GB.%2Fsv%3D1%2Fam%3D!agWx4Vf_ACSIFA91ZQ%2Fd%3D1%2F#id=I1_1323174311773&parent=http%3A%2F%2Fmydomain.com&rpctoken=352111652&_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe.
Domains, protocols and ports must match.
Run Code Online (Sandbox Code Playgroud)
Google网站管理员推荐的代码是不安全的吗?或者我做错了什么?
我想在我的网页上添加规范链接,但是我需要指定域名,还是相关网址呢?
换句话说,是:
<link rel="canonical" href="/item/1">
Run Code Online (Sandbox Code Playgroud)
足够好,还是我需要使用:
<link rel="canonical" href="http://mydomain.com/item/1">
Run Code Online (Sandbox Code Playgroud) 这是我的bash脚本 - 我只想用零填充一组数字:
printf "%04d" "09"
printf "%04d" "08"
printf "%04d" "07"
printf "%04d" "06"
Run Code Online (Sandbox Code Playgroud)
输出:
./rename.sh: line 3: printf: 09: invalid number
0000
./rename.sh: line 4: printf: 08: invalid number
0000
0007
0006
Run Code Online (Sandbox Code Playgroud)
什么...?
只有09和08导致问题:我序列中的每个其他数字似乎都没问题.
javascript ×5
bash ×2
regex ×2
shell ×2
d3.js ×1
ecmascript-5 ×1
google-plus ×1
html ×1
html-head ×1
html-table ×1
http ×1
http-post ×1
match ×1
post ×1
printf ×1
python ×1
seo ×1
url-encoding ×1
urlencode ×1