How identify the form submit button clicked in a variable using Jquery

How can I assign the id of a submit button to a variable using JQuery? I have the following HTML: <form id="myForm"> <input id="oknovo" type="submit" value="OK & Novo" /> <input id="okfechar" type="submit" value="OK & Fechar" /> </form> JS: var botao; $(document).ready(function () { $("#myForm input[type=submit]").click(function (event) {

如何识别使用Jquery在变量中单击的表单提交按钮

如何使用JQuery将提交按钮的ID分配给变量? 我有以下HTML: <form id="myForm"> <input id="oknovo" type="submit" value="OK & Novo" /> <input id="okfechar" type="submit" value="OK & Fechar" /> </form> JS: var botao; $(document).ready(function () { $("#myForm input[type=submit]").click(function (event) { botao = $(this).attr('id'); alert

Declare a global variable from inside a function

I have the following code, necessary to track an embedded Youtube video in my page using their Javascript API: function onYouTubePlayerReady(playerId) { var youtubeplayer = document.getElementById('youtubeplayer'); youtubeplayer.addEventListener("onStateChange", "onytplayerStateChange"); youtubeplayer.setPlaybackQuality('large'); } function onytplayerStateChange(newState

从函数内部声明一个全局变量

我有以下代码,需要使用Javascript API在我的页面中跟踪嵌入的Youtube视频: function onYouTubePlayerReady(playerId) { var youtubeplayer = document.getElementById('youtubeplayer'); youtubeplayer.addEventListener("onStateChange", "onytplayerStateChange"); youtubeplayer.setPlaybackQuality('large'); } function onytplayerStateChange(newState) { //Make it autoplay on page load

html/javascript/php: how do i use a "global variable"?

so my domain name is going to change from building it on my computer (localhost) to what my domain name will be when i actually deploy it, and I don't want to go back and have to change it in a million places. Now i know I could do a superglobal variable in php <?php echo $GLOBALS['domain_name']; ?> but as far as I know you can't use this in separate .js files. How can

html / javascript / php:我如何使用“全局变量”?

所以我的域名将从在我的计算机(本地主机)上构建我的域名变为我实际部署域名时的域名,并且我不想返回并且必须在一百万个地方进行更改。 现在我知道我可以在php中做一个超全局变量 <?php echo $GLOBALS['domain_name']; ?> 但据我所知,你不能在单独的.js文件中使用它。 我如何为我的域名创建一个可以在html和js中使用的“全局变量”? 打印在索引文件的头部(或在PHP中包含在标题标签中) 任何js文件都

Definition vs initialization

What's the difference between declaration, definition and initialization? Example: // Is this a declaration? var foo; // Did I defined object in here (but it is empty)? var foo = {}; // Now that object is initialized with some value? var foo = {first:"number_one"}; The first example is a declaration. You have declared a variable with the identifier foo . You haven't given it a valu

定义vs初始化

声明,定义和初始化有什么区别? 例: // Is this a declaration? var foo; // Did I defined object in here (but it is empty)? var foo = {}; // Now that object is initialized with some value? var foo = {first:"number_one"}; 第一个例子是一个声明。 您已经使用标识符foo声明了一个变量。 你还没有给它一个价值,所以它将是undefined : var foo; console.log(foo); //undefined 第二个例子是一个声明和一个

How to make a variable which is inside a function global?

Following is my javascript function, I want to use variable selected outside function, but I am getting selected not defined error in console of inspect element. window.yourGlobalVariable is not solving my problem. function showMe(pause_btn) { var selected = []; for (var i = 0; i < chboxs.length; i++) { if (chboxs[i].checked) { selected.push(chboxs[i].value);

如何创建一个全局函数内部的变量?

以下是我的javascript函数,我想使用变量选择外部函数,但是我在检查元素的控制台中选择了未定义的错误。 window.yourGlobalVariable没有解决我的问题。 function showMe(pause_btn) { var selected = []; for (var i = 0; i < chboxs.length; i++) { if (chboxs[i].checked) { selected.push(chboxs[i].value); } } } 如果你真的希望它是全球性的,你有两种选择: 在全局声明

How to declare a global variable in JavaScript?

我怎样才能在JavaScript中声明一个全局变量? If you have to generate global variables in production code (which should be avoided) always declare them explicitly : window.globalVar = "This is global!"; While it is possible to define a global variable by just omitting var (assuming there is no local variable of the same name), doing so generates an implicit global, which is a bad thing to do and w

如何在JavaScript中声明一个全局变量?

我怎样才能在JavaScript中声明一个全局变量? 如果您必须在生产代码中生成全局变量(应该避免),请务必 明确声明它们: window.globalVar = "This is global!"; 虽然可以通过仅省略var (假设没有同名的局部变量)来定义全局变量,但这样做会生成隐式全局变量,这是一件坏事,并且会在严格模式下产生错误。 如果这是您要使用此变量的唯一应用程序,则Felix的方法非常出色。 然而,如果你正在编写一个jQuery插件,请考虑jqu

node.js global variables?

I asked here: node.js require inheritance? and was told that I can set variables to the global scope by leaving out the var. This does not work for me. ie: _ = require('underscore'); Does not make the _ available on required files. I can set with express's app.set and have it available elsewhere though. Can somebody confirm that this is supposed to work? Thanks. global._ = requir

node.js全局变量?

我在这里问:node.js需要继承? 并被告知我可以通过忽略var来将变量设置为全局范围。 这对我不起作用。 即: _ = require('underscore'); 不要在必需的文件中使用_。 我可以用express的app.set来设置它,但它可以在其他地方使用。 有人可以证实,这是应该工作? 谢谢。 global._ = require('underscore') 在节点中,可以通过“global”或“GLOBAL”对象设置全局变量: GLOBAL._ = require('underscore'); // but you "s

Not defining the type of variable (Automatic global variables)

This question already has an answer here: Define global variable in a JavaScript function 11 answers In JavaScript, creating a variable without var is the same as setting it on the global object as a property (and in the browser, global is window : nameWithoutVar = 1; // the above is the same as window.nameWithoutVar = 1; This means that any other script loaded in the browser for the page c

不定义变量的类型(自动全局变量)

这个问题在这里已经有了答案: 在JavaScript函数中定义全局变量11个答案 在JavaScript中,不使用var创建变量与在全局对象上将其设置为属性相同(并且在浏览器中, global是window : nameWithoutVar = 1; // the above is the same as window.nameWithoutVar = 1; 这意味着在页面的浏览器中加载的任何其他脚本都可以访问nameWithoutVar ,就像访问location , document等一样。 由于这个原因,全局变量被认为是一个非常

Is it possible to make global Variable in JAVASCRIPT?

This question already has an answer here: Define global variable in a JavaScript function 11 answers Within the global scope (aka "window"), variables are global. Check this out: //this is global because it is in the global scope (the window) var foo = 'stuff'; //because it is global (window) you can also access it like this: console.log(window.foo); //'stuff' Now you can access

是否有可能在JAVASCRIPT中创建全局变量?

这个问题在这里已经有了答案: 在JavaScript函数中定义全局变量11个答案 在全球范围内(又称“窗口”),变量是全球性的。 看一下这个: //this is global because it is in the global scope (the window) var foo = 'stuff'; //because it is global (window) you can also access it like this: console.log(window.foo); //'stuff' 现在你可以在任何地方访问foo 。 值得注意的是全局变量不是最佳实践 - 所以请查看面

How to make a local variable into Global? JavaScript

This question already has an answer here: Define global variable in a JavaScript function 11 answers You can do the following to access a global inside of a function. Any variable created outside the scope of a function can be reference inside of a function. Var myGlobalVar; Function myFunction(){ if(....) { myGlobalVar = 1; } } You don't. You can copy a local variabl

如何使本地变量进入Global? JavaScript的

这个问题在这里已经有了答案: 在JavaScript函数中定义全局变量11个答案 您可以执行以下操作来访问函数内部的全局内容。 任何在函数范围外创建的变量都可以在函数内部引用。 Var myGlobalVar; Function myFunction(){ if(....) { myGlobalVar = 1; } } 你没有。 您可以通过执行window.myVar = myVar (无论您是全局对象替换window来将局部变量复制到全局范围,但是如果您重新分配本地变量,则全局副本