为什么UUID的格式为"8-4-4-4-12"(数字)?我已经看了看原因,但找不到要求它的决定.
格式为十六进制字符串的UUID示例:58D5E212-165B-4CA0-909B-C86B9CEE0111
我想在我的网站上显示YouTube视频,但我需要id为每个将由用户共享的视频添加唯一视频.所以我把它放在一起,我遇到了一个小问题.我试图让JavaScript为div添加一个随机字符串id,但它不起作用,显示字符串:
<script type='text/javascript' src='jwplayer.js'></script>
<script type='text/javascript'>
function randomString(length) {
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'.split('');
if (! length) {
length = Math.floor(Math.random() * chars.length);
}
var str = '';
for (var i = 0; i < length; i++) {
str += chars[Math.floor(Math.random() * chars.length)];
}
return str;
}
var div = randomString(8);
</script>
<div id='div()'>This text will be replaced</div>
<script type='text/javascript'>
jwplayer('div()').setup({
'flashplayer': 'player.swf',
'file': 'http://www.youtube.com/watch?v=4AX0bi9GXXY',
'controlbar': 'bottom',
'width': '470',
'height': '320'
});
</script>
Run Code Online (Sandbox Code Playgroud) 是否有解决下面代码中说明的问题的方法?首先在浏览器中打开代码直接到达关键点,而不必在知道您要查找的内容之前查看所有代码.
<html>
<head>
<title>Input ID creates problems</title>
<style type="text/css">
#prologue, #summary { margin: 5em; }
</style>
</head>
<body>
<h1>Input ID creates a bug</h1>
<p id="prologue">
In this example, I make a list of checkboxes representing things which could appear in a book. If you want some in your book, you check them:
</p>
<form>
<ul>
<li>
<input type="checkbox" id="prologue" />
<label for="prologue">prologue</label>
</li>
<li>
<input type="checkbox" id="chapter" />
<label for="chapter">chapter</label>
</li>
<li>
<input type="checkbox" id="summary" />
<label for="summary">summary</label>
</li>
<li> …Run Code Online (Sandbox Code Playgroud) 有没有人知道TypeScript中的一个好的,可靠的C#实现GUID(UUID)?
可以自己做,但想到如果其他人以前做过,我会节省时间.
我想创建像记录器一样跟踪用户的所有动作.为此,我需要识别用户与之交互的元素,以便我可以在以后的会话中引用这些元素.
用伪代码说,我希望能够做类似以下的事情
示例HTML(可能有任何复杂性):
<html>
<body>
<div class="example">
<p>foo</p>
<span><a href="bar">bar</a></span>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
用户点击某些内容,例如链接.现在我需要识别被点击的元素并将其位置保存在DOM树中以供以后使用:
(any element).onclick(function() {
uniqueSelector = $(this).getUniqueSelector();
})
Run Code Online (Sandbox Code Playgroud)
现在,uniqueSelector应该是这样的(我不介意它是xpath还是css选择器样式):
html > body > div.example > span > a
Run Code Online (Sandbox Code Playgroud)
这将提供保存该选择器字符串并在以后使用它来重放用户所做的操作的可能性.
怎么可能?
得到了我的答案:为元素获取jQuery选择器
我有一个表单,用户可以为多个城市添加多个选择框.问题是每个新生成的选择框都需要具有唯一的ID.可以这样做是JavaScript吗?
更新:这是选择城市的表格的一部分.另请注意,当选择特定状态时,我正在使用一些php来填充城市.
<form id="form" name="form" method="post" action="citySelect.php">
<select id="state" name="state" onchange="getCity()">
<option></option>
<option value="1">cali</option>
<option value="2">arizona</option>
<option value="3">texas</option>
</select>
<select id="city" name="city" style="width:100px">
</select>
<br/>
</form>
Run Code Online (Sandbox Code Playgroud)
这是javascript:
$("#bt").click(function() {
$("#form").append(
"<select id='state' name='state' onchange='getCity()'>
<option></option>
<option value='1'>cali</option>
<option value='2'>arizona</option>
<option value='3'>texas</option>
</select>
<select id='city' name='city' style='width:100px'></select><br/>"
);
});
Run Code Online (Sandbox Code Playgroud) 我正在使用这段JavaScript生成一个UID:
(原版的:)
//If ID has not been defined then generate a new unique ID.
if(!id){
id = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); });
}
Run Code Online (Sandbox Code Playgroud)
(格式化,以便可以阅读:)
// If ID has not been defined then generate a new unique ID.
if (!id) {
id = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
/[xy]/g,
function (c) {
var r = Math.random() * 16 | 0,
v = …Run Code Online (Sandbox Code Playgroud) 我有一个excel文件,每行有一个订单,我希望每个订单都有一个唯一的标识符,因此会有一个唯一ID列.每次我填写一行,我希望Excel为我自动填充唯一ID列.我做了一些研究,并指出了GUID的方向.我找到了以下代码:
Function GenGuid() As String
Dim TypeLib As Object
Dim Guid As String
Set TypeLib = CreateObject("Scriptlet.TypeLib")
Guid = TypeLib.Guid
' format is {24DD18D4-C902-497F-A64B-28B2FA741661}
Guid = Replace(Guid, "{", "")
Guid = Replace(Guid, "}", "")
Guid = Replace(Guid, "-", "")
GenGuid = Guid
End Function
Run Code Online (Sandbox Code Playgroud)
但我不确定如何实现它.任何帮助将不胜感激.先感谢您.
我希望能够基于散列字符串为用户创建唯一的令牌*.我知道我可以,例如,使用md5()库,但由于目的不是加密,我想知道是否有任何我可以"开箱即用"的东西.原生JavaScript中是否有任何单向散列函数?
*我意识到这些并不是严格独特的.我很可能有很小的哈希碰撞机会.
使用新的Firebase API,您可以从客户端代码将文件上传到云存储.这些示例假定文件名在上载期间已知或是静态的:
// Create a root reference
var storageRef = firebase.storage().ref();
// Create a reference to 'mountains.jpg'
var mountainsRef = storageRef.child('mountains.jpg');
// Create a reference to 'images/mountains.jpg'
var mountainImagesRef = storageRef.child('images/mountains.jpg');
Run Code Online (Sandbox Code Playgroud)
要么
// File or Blob, assume the file is called rivers.jpg
var file = ...
// Upload the file to the path 'images/rivers.jpg'
// We can use the 'name' property on the File API to get our file name
var uploadTask = storageRef.child('images/' + file.name).put(file);
Run Code Online (Sandbox Code Playgroud)
用户上传自己的文件时,名称冲突将成为一个问题.如何让Firebase创建文件名而不是自己定义?是否有类似push() …