我需要为元素添加第二个唯一ID.
我用它来生成新的ID
var id = 1;
function getNextId()
{
return ++id;
}
Run Code Online (Sandbox Code Playgroud)
然后我这样做
$('<div id="content '" + getNextId() +"'" class="span6"></div>').appendTo('.new');
Run Code Online (Sandbox Code Playgroud)
但我得到了一个 Uncaight SyntaxError: Unexpected identifier
如何添加多个ID,其中第二个是唯一的?
(我在点击时删除了第一个ID,所以我可以将#content留在那里)
抓取子串:
var hash = document.location.hash;
// create an object to act like a dictionary to store each value indexed by its key
var partDic = {};
// remove the leading "#" and split into parts
var parts = hash.substring(1).split('&');
// If you just want the first value, whatever it is, use this.
// But be aware it's a URL so can be set to anything in any order, so this makes little sense
// var string = parts[0].split('=')[1];
// build …Run Code Online (Sandbox Code Playgroud) 我这样做但是没有用
HTML
<a href="#filter-year-y2013" data-filter-value=".y2013">2013</a>
Run Code Online (Sandbox Code Playgroud)
jQuery的
var token = document.location.href.split('=')[1];
var attribu = "." + token;
$('a[data-filter-value= attribu]').css("background", "#ddd");
Run Code Online (Sandbox Code Playgroud)
让我们说:
_Example
_1979
Run Code Online (Sandbox Code Playgroud)
我们怎么知道后面的字符_是a number还是a letter?我不熟悉regex.
这是我正在做的只是找到字符串开头_然后我删除,_因为我只是出于其他原因使用它:
if (strpos($txt, '_') !== false) {
$output = str_replace('_', ' ', $txt);
echo $output;
...Now I should find if the first `character` is a `letter` or a `number`
Run Code Online (Sandbox Code Playgroud) 我首先要说的是,我已经看过很多这样的答案,而这个是最接近的。
所以基本上我做了:
var defaultLatLong = {
lat: 45.4655171,
lng: 12.7700794
};
var map = new google.maps.Map(document.getElementById('map'), {
center: defaultLatLong,
zoom: 3,
minZoom: 3,
restriction: {
latLngBounds: {
east: 180,
north: 85,
south: -85,
west: -180
},
strictBounds: true
}, ...
Run Code Online (Sandbox Code Playgroud)
但这会阻止在左/右平移时进行顶部/底部平移。
知道为什么吗?
UDP日期
我尝试了以下方法:
var allowedBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(85, 180),
new google.maps.LatLng(-85, -180)
);
var lastValidCenter = map.getCenter();
google.maps.event.addListener(map, 'center_changed', function() {
if (allowedBounds.contains(map.getCenter())) {
// still within valid bounds, so save the last valid position …Run Code Online (Sandbox Code Playgroud) 我有一个像这样结构的json:
{
"total": 4367,
"page": 1,
"per_page": 10,
"paging": {
"next": "/videos?query=second%20world%20war&per_page=10&access_token=XXX&page=2",
"previous": null,
"first": "/videos?query=second%20world%20war&per_page=10&access_token=XXX&page=1",
"last": "/videos?query=second%20world%20war&per_page=10&access_token=XXX&page=437"
},
"data": [
{
"uri": "/videos/128373915",
"name": "The Fallen of World War II",
Run Code Online (Sandbox Code Playgroud)
我需要访问name并尝试:
$.ajax( {
type: "GET",
url: url,
dataType: 'json',
success: vimeoResultsFunc
});
function vimeoResultsFunc(data){
for (var i = 0; i < data.length; i++) {
console.log(data[i].name);
}
}
Run Code Online (Sandbox Code Playgroud)
但我一无所获