对于我的Greasemonkey脚本,有部分代码应该在页面加载(@run-at document-start)之前运行,而另一部分代码应该在文档加载后运行(@run-at document-end).
这可能吗?
我宁愿不使用jQuery.
我尝试了这个onload活动,但它没有用.我认为如果文件还没有,那么事件就无法附上了?
window.document.onload = function(e){
alert("document.onload" );
}
Run Code Online (Sandbox Code Playgroud) 如何获取作为(e)传递的元素的ID?
window.addEventListener('load', function(){
var tags = document.getElementsByClassName("tag");
for (i=0; i<tags.length; i++){
tags[i].addEventListener('mousedown', function(e){ tagClick(e) }, false);
}
}, false);
function tagClick(e){
/* here I'm gonna need the event to cancel the bubble and the ID to work with it*/
alert('The id of the element you clicked: ' + [?object].id);
[?object].className='newClass';
e.stopPropagation();
e.cancelBubble = true;
}
Run Code Online (Sandbox Code Playgroud)
我需要在tagClick中获取元素/对象,以便我可以更改其属性
HTML:
<div class="tag">
<img src="/images/tags/sample.jpg"/>
<label class="tagLabel">Sample</label>
</div>
Run Code Online (Sandbox Code Playgroud)
请注意,附加事件的元素是div,但是当使用e.srcElement时,ig会给我图像对象.
我正在寻找正确的方法来分发/部署一个 node.js 应用程序,该应用程序将作为用户机器上的小型网络服务器运行。
是否有存根方法或安装脚本或“安装向导”可以下载所有node_modules依赖项、下载最新的 nodejs 二进制文件、设置环境等......或者我必须将所有内容打包分发?有没有为此目的的指南?
我有这个例子,不能创建customers_b.错误代码1005 /错误号:121.但是,如果我首先创建customers_b而不是customers_a,那么customers_a就是那个不会被创建的.
怎么了?为什么我不能将多个FK链接到PK'id_state'?谢谢!
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
DROP SCHEMA IF EXISTS `testdb` ;
CREATE SCHEMA IF NOT EXISTS `testdb` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `testdb` ;
-- -----------------------------------------------------
-- Table `testdb`.`state`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `testdb`.`state` ;
CREATE TABLE IF NOT EXISTS `testdb`.`state` (
`id_state` INT NOT NULL,
`abbr` CHAR(2) NOT NULL,
PRIMARY KEY (`id_state`),
UNIQUE INDEX `id_state_UNIQUE` (`id_state` ASC))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `testdb`.`customers_a`
-- ----------------------------------------------------- …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写此regEx(javascript)来匹配word1和word2(当它存在时):
This is a test. Here is word1 and here is word2, which may or may not exist.
我试过这些:
(word1).*(word2)?
这只会匹配,word1无论是否word2存在.
(word1).*(word2)
这将匹配两者,但仅在两者都存在时才匹配.
我需要一个正则表达式匹配word1和word2 - 可能存在也可能不存在.
我正在尝试使用下面的代码绘制画布.alert()返回undefined.看起来文档已准备好但画布不是.
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/myscript.js"></script>
<link type="text/css" rel="stylesheet" href="css/normalize.css" media="screen" />
<title></title>
</head>
<body>
<canvas id="space" width="1500" height="1500"></canvas>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
myscript.js
$(document).ready(function(){
//$(window).load(function() {
alert($('#space').id); // returns undefined
dbCanvas = $('#space');
context = dbCanvas.getContext('2d');
// IE: {exception} Object doesn't support property or method 'getContext'
// FF: TypeError: dbCanvas.getContext is not a function
context.fillStyle = "rgb(200, 0, 0)";
context.fillRect(10, 10, 55, 50);
});
Run Code Online (Sandbox Code Playgroud) 为什么node.js允许更改指定为常量的模块(或对象)?
例如,允许这样做:
const EXPRESS = require('express');
EXPRESS.someProperty = 'some value';
Run Code Online (Sandbox Code Playgroud)
但这不是:
const MYCONST = '123';
MYCONST = '456';
Run Code Online (Sandbox Code Playgroud) 我想出了这个理论,以避免密码窃取形式的POST嗅探.想法是连接一个salt字符串(在php session_start()上随机生成).

请注意,salt_hash是在每次访问时随机生成的...它不是在客户端计算的.
基本上JS代码将添加到HTML:
<script>
var salt_hash='654236426556424655643645462321560356';
</script>
Run Code Online (Sandbox Code Playgroud)
然后在发布之前,我会计算......
cryptoPass = md5(md5(password)+salt_hash);
passowrd = ''; // clear user password input
submit POST...;
Run Code Online (Sandbox Code Playgroud)
然后在login.php上我将$ _POST ['cryptoPass']与md5进行比较(用md5存储的MySQL用户密码加上salt_hash)
它真的会起作用还是一个无意义的理论?
我在Javascript中使用此正则表达式删除3个字母或更少的字词:
srcText = srcText.replace(/\s[a-z]{1,3}\s/gi,'');
Run Code Online (Sandbox Code Playgroud)
它可以工作但是当找到两个连续匹配时,第二个不受影响:
例:
"......这是一个文本样本......"
除非我再次运行代码,否则'one'和'a'不会受到影响:
srcText = srcText.replace(/\s[a-z]{1,3}\s/gi,'');
Run Code Online (Sandbox Code Playgroud)
所以我必须运行代码n次,n是srcText中的连续匹配.
用于测试目的:
示范文本:
http://www.gutenberg.org/files/521/521-0.txt(比方说,第4段)
我的正则表达式遗漏了什么或javascript不允许这种递归?
我正在寻找一种以更有效的方式编写此代码的方法.在对象加载方法中,它将具有与选项中的条目一样多的行(至少).
var myPlugin = {
// here are the 'plugin' default ptions
option1: 'deafult1'
, option2: 'deafult2'
, option3: false
, option4: true
, optionN: 'deafultN'
// here the plugin will receive an object ('options')
load: function(options){
if (options.option1) myPlugin.option1 = options.option1;
if (options.option2) myPlugin.option2 = options.option2;
//...
}
}
myPlugin.load({
option3: true
, option5: '123'
});
Run Code Online (Sandbox Code Playgroud)
这是将选项加载到JS/jquery插件的正确方法吗?有没有办法使用for ()/ each()以更有效/整洁的方式加载选项对象?
我想的是:
load: function(options){
$.each(options, function(index, opt){
// how to load options from here? …Run Code Online (Sandbox Code Playgroud) javascript ×7
jquery ×2
node.js ×2
regex ×2
create-table ×1
ecmascript-6 ×1
events ×1
greasemonkey ×1
html5 ×1
json ×1
md5 ×1
mysql ×1
object ×1
post ×1
security ×1
startup ×1