Jquery create element initially hidden

Is there a way to create an element and have it hidden initially? I am creating an iframe but don't want it shown right away. Very simple. Just do this: var myFrame = $("<iframe>").hide(); Just create it and style it as being hidden, in one of many possible ways, like this: var secretThing = $('<iframe></iframe>', { css: { 'display': 'none' }}); $('body').append(secre

jQuery创建初始隐藏的元素

有没有办法创建一个元素,并最初隐藏它? 我正在创建一个iframe,但不希望它马上显示。 很简单。 只要这样做: var myFrame = $("<iframe>").hide(); 只需创建它并以隐藏的方式进行设置,就可以通过以下几种方式之一进行设置: var secretThing = $('<iframe></iframe>', { css: { 'display': 'none' }}); $('body').append(secretThing); 隐藏某种东西的另一种方法是将其放置在远离视口的位置,或将

How To call the same Method for different Elements with different IDs?

Lets say i have 3 p-Elements. If i click on one of them its Text should change. But how can i do it without writing a Method for every Element? <!DOCTYPE html> <html> <body> <p>This example uses the HTML DOM to assign an "onclick" event to a p element.</p> <p id="demo">Click me.</p> <p id="demo2">Click me.</p> <script> document

如何针对具有不同ID的不同元素调用相同的方法?

可以说我有3个p元素。 如果我点击其中一个文本应该改变。 但是我怎么能不用为每个元素编写一个方法? <!DOCTYPE html> <html> <body> <p>This example uses the HTML DOM to assign an "onclick" event to a p element.</p> <p id="demo">Click me.</p> <p id="demo2">Click me.</p> <script> document.getElementById("demo").onclick = function() {myF

Multiples checkboxes same .click function

Apologies for my lack of knowledge, I'm sure this is one of those simple fix solutions. I have a number of checkboxes in my web page. When you check a check box a value of 1 is sent to a variable. See example: $('#abilitytobenonjudgemental').click(function(){ var check = document.getElementById("abilitytobenonjudgemental").checked if (check == true) { job2 += 1; job3

倍数复选框相同.click功能

对于我缺乏知识抱歉歉,我确信这是那些简单的修复解决方案之一。 我的网页中有一些复选框。 当您选中复选框时,值1会发送给变量。 看例子: $('#abilitytobenonjudgemental').click(function(){ var check = document.getElementById("abilitytobenonjudgemental").checked if (check == true) { job2 += 1; job3 += 1; job7 += 1; workSkillsCheckboxCount += 1; console.log(workSkills

jQuery function to avoid copy/paste

I have a jQuery to load div content by year (from 2008 to current year). Here is my code : $('.filtre .f2017').click(function() { $('.loader').show().delay(7000).fadeOut(); $('.selected .homeliVa li').hide('slow'); $('.homeliDp .itemCom').hide('slow'); $('.selected .homeliAlm li').hide('slow'); setTimeout('$(".selected .annee2017").show()', 5000); $('.selected .nothing'

jQuery函数避免复制/粘贴

我有一个jQuery来加载div内容年份(从2008年到今年)。 这是我的代码: $('.filtre .f2017').click(function() { $('.loader').show().delay(7000).fadeOut(); $('.selected .homeliVa li').hide('slow'); $('.homeliDp .itemCom').hide('slow'); $('.selected .homeliAlm li').hide('slow'); setTimeout('$(".selected .annee2017").show()', 5000); $('.selected .nothing').show('slow'); $('.

Best practice syntactically for multiple jQuery selectors

If I were to bind a click event to a lot of different selectors using jQuery like the following: scrollToPoint('.main-nav a, .sub-nav a, .enquire-btn, #showcase-list a, #showcase-more-info a.back-btn') What is the industry standard method to lay this out syntactically and is their an alternative approach? 我认为这是最好的方法如果你确定你想要很多选择者: var selectors = [ ".main-nav a",

语法上适用于多个jQuery选择器的最佳实践

如果我要使用如下所示的jQuery将点击事件绑定到很多不同的选择器: scrollToPoint('.main-nav a, .sub-nav a, .enquire-btn, #showcase-list a, #showcase-more-info a.back-btn') 什么是行业标准方法,以语法形式表达并且是他们的替代方法? 我认为这是最好的方法如果你确定你想要很多选择者: var selectors = [ ".main-nav a", ".sub-nav a", ".all", ".other", ".selectors" ]; scrollToPoin

How to set same url for different elements

This question already has an answer here: jQuery same click event for multiple elements 9 answers You could set a home page variable and just use that like so var homePageUrl = "http://realestatecenter.bankofamerica.com/" and just pass window.location.href = homePageUrl you could also make it its own function like function redirect(path) { window.location.href = path } and then call th

如何为不同元素设置相同的网址

这个问题在这里已经有了答案: 对于多个元素jQuery相同的点击事件9个答案 你可以设置一个主页变量,并像这样使用 var homePageUrl = "http://realestatecenter.bankofamerica.com/" 并传递给window.location.href = homePageUrl 你也可以使它像自己的功能 function redirect(path) { window.location.href = path } 然后在url中作为参数在每个地方调用该函数,至少您将所有内容都采用一种函数与重复代码

How can i use this script with 2 buttons

This question already has an answer here: jQuery same click event for multiple elements 9 answers 你可以这样做: $('.downloadButton,.downloadButtonUS')

我怎样才能用这个脚本与2个按钮

这个问题在这里已经有了答案: 对于多个元素jQuery相同的点击事件9个答案 你可以这样做: $('.downloadButton,.downloadButtonUS')

How to target all inputs on the page?

This question already has an answer here: jQuery same click event for multiple elements 9 answers Use querySelectorAll to select all the elements matching selector. To select all the input type number elements. var allNumberInputs = document.querySelectorAll('input[type="number"]'); Updated Fiddle Then you need to update the code that binds event on the elements. Loop over all the match

如何定位页面上的所有输入?

这个问题在这里已经有了答案: 对于多个元素jQuery相同的点击事件9个答案 使用querySelectorAll来选择所有匹配选择器的元素。 选择所有输入类型的number元素。 var allNumberInputs = document.querySelectorAll('input[type="number"]'); 更新小提琴 然后,您需要更新绑定元素事件的代码。 遍历所有匹配的元素并分别绑定每个元素上的事件。 // Select your input element. var numInput = document.querySelectorAll

How do I view events fired on an element in Chrome DevTools?

I have a customizable form element on a page from a library. I want to see what javascript events are fired when I interact with it because I am trying to find out which event handler to use. How do I do that using Chrome Web Developer? Hit F12 to open Dev Tools Click the Sources tab On right-hand side, scroll down to "Event Listener Breakpoints", and expand tree Click on the

如何查看在Chrome DevTools中的元素上触发的事件?

我在库中的页面上有一个可自定义的表单元素。 我想查看当我与它交互时发生了什么JavaScript事件,因为我试图找出使用哪个事件处理程序。 我如何使用Chrome Web Developer做到这一点? 点击F12打开开发工具 点击Sources选项卡 在右侧,向下滚动到“Event Listener Breakpoints”,然后展开树 点击你想听的事件。 与目标元素进行交互,如果他们触发,您将在调试器中获得一个中断点 同样,你可以右键单击目标元素 - &g

How to find event listeners on a DOM node when debugging or from the JavaScript code?

I have a page where some event listeners are attached to input boxes and select boxes. Is there a way to find out which event listeners are observing a particular DOM node and for what event? Events are attached using: Prototype's Event.observe ; DOM's addEventListener ; As element attribute element.onclick . If you just need to inspect what's happening on a page, you might

如何在调试时或从JavaScript代码查找DOM节点上的事件侦听器?

我有一个页面,一些事件监听器连接到输入框和选择框。 有没有办法找出哪些事件监听器正在观察特定的DOM节点以及哪些事件? 活动使用: Prototype的Event.observe ; DOM的addEventListener ; 作为元素属性element.onclick 。 如果您只需要检查页面上发生了什么,则可以尝试Visual Event书签。 更新 :可用的视觉事件2; 这取决于事件如何附加。 为了说明,假定我们有以下的点击处理程序: var handler = function(