Questions tagged «javascript»

有关在ECMAScript(JavaScript / JS)及其各种方言/实现(不包括ActionScript)中进行编程的问题。此标记很少单独使用,但最常与标记[node.js],[jquery],[json]和[html]关联。

3
如何访问电子中的DOM元素?
我正在尝试向index.html文件中的按钮添加功能,如下所示:我在按钮元素中index.html <button id="auth-button">Authorize</button> 在main.js应用程序中,我有 require('crash-reporter').start(); console.log("oh yaeh!"); var mainWindow = null; app.on('window-all-closed', function(){ if(process.platform != 'darwin'){ app.quit(); } }); app.on('ready',function(){ mainWindow = new BrowserWindow({width:800, height : 600}); mainWindow.loadUrl('file://' + __dirname + '/index.html'); var authButton = document.getElementById("auth-button"); authButton.addEventListener("click",function(){alert("clicked!");}); mainWindow.openDevTools(); mainWindow.on('closed',function(){ mainWindow = null; }); }); 但是会发生如下错误: Uncaught Exception: ReferenceError: document is …


6
jQuery按键箭头键
我正在尝试捕获jQuery中的箭头按键,但是没有事件被触发。 $(function(){ $('html').keypress(function(e){ console.log(e); }); }); 这会为字母数字键生成事件,但是删除,箭头键等不会生成事件。 我没有抓到这些错在做什么?

6
如何检查Node.js中是否定义了变量?
我正在开发实际上是js的node.js中的程序。 我有一个变量: var query = azure.TableQuery... 看起来这行代码没有执行过一段时间。 我的问题是: 我该如何做类似的情况: if this variable is defined do this. else do this. 我不能用js做 (query!= null) 我想看看是否已定义此变量,请执行某些操作。这该怎么做

4
Chrome扩展程序如何将许多文件保存到用户指定的目录中?
我正在开发一个Chrome扩展程序以用作内部工具。它要求的行为是: 作为页面操作,请在查看某些Intranet页面时启用地址栏图标。 当用户单击该图标时,在页面上标识某种特定媒体类型(例如.jpg)的所有文件,以及 将它们全部静默保存到用户本地驱动器上的目录中。 之前曾有人问过这个问题,但是答案是“使用NPAPI ”,现在NPAPI被遗弃了。 那么,目前可用的方法是什么?我看过的是: 该chrome.FileSystem API ---但这不保存任何用户访问的位置的文件。而是将存储的文件隐藏在未记录目录中的混淆名称后面。用户要求将文件以其原始名称存储在可访问的目录中。 HTML5下载属性,方法是创建数据:URL并以编程方式单击它。这会为每个文件弹出一个“另存为...”对话框,当单个页面上有一百个资产时,这是不可接受的。用户要求下载文件时,除了单击单个图标外,不能进行进一步的交互。 该浏览器下载API,但那只是在测试和开发渠道提供。用户需要与主流Chrome一起使用此扩展程序。 使用Native Messaging API,方法是创建一个小的.exe,将文件保存到磁盘,然后将.jpg作为blob传递给它。这似乎很麻烦,我什至不确定如何可靠地将大型Blob传递给EXE。 我可以尝试另一种方法吗?


3
从主文档中的JavaScript获取IFrame的文档
我有这个HTML代码: <html> <head> <script type="text/javascript"> function GetDoc(x) { return x.document || x.contentDocument || x.contentWindow.document; } function DoStuff() { var fr = document.all["myframe"]; while(fr.ariaBusy) { } var doc = GetDoc(fr); if (doc == document) alert("Bad"); else alert("Good"); } </script> </head> <body> <iframe id="myframe" src="http://example.com" width="100%" height="100%" onload="DoStuff()"></iframe> </body> </html> 问题是我收到消息“错误”。这意味着iframe的文档未正确获取,而GetDoc函数实际返回的是父文档。 如果您告诉我在哪里犯错,我将不胜感激。(我想将文档托管在IFrame中。) …

7
如何通过JavaScript数组中的键和值查找对象的索引
鉴于: var peoples = [ { "attr1": "bob", "attr2": "pizza" }, { "attr1": "john", "attr2": "sushi" }, { "attr1": "larry", "attr2": "hummus" } ]; 通缉: 对象的索引,attr === value例如attr1 === "john"或attr2 === "hummus" 更新: 请仔细阅读我的问题,我既不想通过$ .inArray查找对象,也不想获取特定对象属性的值。请考虑这个作为您的答案。谢谢!

11
如何更改dropzone.js中的默认文本?
我正在使用dropzone.js上载文件。但是,我很难更改默认文本。 我尝试实例化dropzone类: $(document).ready(function(){ $(".foo").dropzone({ dictDefaultMessage: "hello" }); }); 有了这个标记: <div class="span4"> <form action="http://localhost/post" method="post" accept-charset="utf-8" id="drop3" class="foo" enctype="multipart/form-data"> </form> </div> <div class="span4"> <form action="http://localhost/post" method="post" accept-charset="utf-8" id="drop4" class="foo" enctype="multipart/form-data"> </form> </div> 当然,这使我能够上传文件,但是默认文本为空白。 我测试了以下内容: $(".foo").dropzone(); 我似乎得到了相同的结果-没有默认文字。所以..如何更改默认文本?



8
通过JavaScript检查单选按钮组的值?
这看起来很愚蠢和愚蠢,但是我似乎无法弄清楚如何通过JavaScript检查HTML表单中单选按钮组的值。我有以下代码: <input type="radio" id="genderm" name="gender" value="male" /> <label for="genderm">Male</label> <input type="radio" id="genderf" name="gender" value="female" /> <label for="genderf">Female</label> 如何gender通过JavaScript检索值?

5
HTML5动态创建画布
嗨,我有一个关于使用JavaScript动态创建画布的问题。 我创建一个这样的画布: var canvas = document.createElement('canvas'); canvas.id = "CursorLayer"; canvas.width = 1224; canvas.height = 768; canvas.style.zIndex = 8; canvas.style.position = "absolute"; canvas.style.border = "1px solid"; 但是当我尝试找到它时,我得到了一个null值: cursorLayer = document.getElementById("CursorLayer"); 我做错了吗?有没有更好的方法使用JavaScript创建画布?

3
如何在流中使用ES8异步/等待?
在https://stackoverflow.com/a/18658613/779159中,示例了如何使用内置的加密库和流来计算文件的md5。 var fs = require('fs'); var crypto = require('crypto'); // the file you want to get the hash var fd = fs.createReadStream('/some/file/name.txt'); var hash = crypto.createHash('sha1'); hash.setEncoding('hex'); fd.on('end', function() { hash.end(); console.log(hash.read()); // the desired sha1sum }); // read all file and pipe it (write it) to the hash object …

26
javascript密码生成器
什么是创建一个包含8个字符的随机密码的最佳方法a-z,A-Z以及0-9? 绝对没有安全问题,这仅是用于原型制作,我只希望看起来真实的数据。 我当时正在考虑for (0 to 7) Math.random产生ASCII码并将其转换为字符。你有什么其他的建议?
74 javascript 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.