onclick

Why does my jQuery click handler appear to run multiple times for some of its targets?

半腔热情 提交于 2019-12-19 05:18:10
问题 I apply: $(".newContentLink").click(function() { $("#test").append("1"); }); On this: <span id="contents"> <input class="newContentLink" type="submit" style="width: 100%;" value="CREATE A NEW CONTENT"/> <span id="content1" class="content study"> </span> <input class="newContentLink" type="submit" style="width: 100%;" value="CREATE A NEW CONTENT"/> <span id="content3" class="content study"> </span> <input class="newContentLink" type="submit" style="width: 100%;" value="CREATE A NEW CONTENT"/>

Why does my jQuery click handler appear to run multiple times for some of its targets?

老子叫甜甜 提交于 2019-12-19 05:18:05
问题 I apply: $(".newContentLink").click(function() { $("#test").append("1"); }); On this: <span id="contents"> <input class="newContentLink" type="submit" style="width: 100%;" value="CREATE A NEW CONTENT"/> <span id="content1" class="content study"> </span> <input class="newContentLink" type="submit" style="width: 100%;" value="CREATE A NEW CONTENT"/> <span id="content3" class="content study"> </span> <input class="newContentLink" type="submit" style="width: 100%;" value="CREATE A NEW CONTENT"/>

JavaScript button onclick not working

a 夏天 提交于 2019-12-19 05:09:39
问题 <button onclick="hello()">Hello</button> <script> function hello() { alert('Hello'); } </script> This is my code. But it's not working. When I click on the button nothing happens. 回答1: How about this? <button id="hellobutton">Hello</button> <script> function hello() { alert('Hello'); } document.getElementById("hellobutton").addEventListener("click", hello); </script> P.S. You should place hello() above of the button. 回答2: Note to other developers coming across this, you can run into this if

JavaScript制作简单的计算器

给你一囗甜甜゛ 提交于 2019-12-19 04:17:26
使用js来实现一个简单的计算器功能,包括加减乘除以及清空内容。 下面的HTML的代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <div id="jisuandiv"> <h2>js计算器</h2> <input type="text" id="text" value="" disabled="disabled"/> <br> <div id="jisuankuang"> <button type="button" onclick="cale(this.id)" id="7" value="7">7</button> <button type="button" onclick="cale(this.id)" id="8" value="8">8</button> <button type="button" onclick="cale(this.id)" id="9" value="9">9</button> <button type="button" onclick="cale(this.id)" id="*" value="*">*</button> <button type="button" onclick="cale(this.id)" id="4"

Onclick play GIF image with jQuery and start from beginning

这一生的挚爱 提交于 2019-12-19 03:59:40
问题 I have a website with images on it. Some of the images are animated GIF images. What I've done is to show a static image of the GIF and on a click event, the actual GIF images is displayed. Here is my code: JQuery $(".theimage").click(function() { $(this).addClass('hidden'); $(this).next().removeClass('hidden'); }); $(".theimage2").click(function() { $(this).addClass('hidden'); $(this).prev().removeClass('hidden'); }); HTML <img class="theimage" src="image_static.gif" alt=""/> <img class=

javascript window.open not working in safari and chrome

☆樱花仙子☆ 提交于 2019-12-19 03:39:38
问题 I have a div element. The div is an icon. When you click on this icon is triggered a form submit. On the form submit there are some calculations and with the result of those calculations a new tab is opened. I use the " window.open(url, '_blank'); " But in safari and chrome this new tab is seen as a popup and is blocked. I tried to create a hidden a href and to trigger click so it will open the page in new tab, but it doesn't work. Any idea how to fix this? EDIT - SOLUTION FOUND You need to

Javascript: Functions get called on page load instead of onclick/onsubmit

丶灬走出姿态 提交于 2019-12-19 02:52:12
问题 I'm relatively new to JS, but I have programmed in C before, and I'm trying to get my head around the whole event driven nature of it. I'm trying to create a script that will validate form input, however all of my code is being run - everything inside if/else, loops, what have you - regardless of the event happening or not. To test, and to make it easier to post here, I've written a simple program that has this problem too. HTML: <button id="test">Test</button> Javascript: function init(){

webkit / Chrome history.back(-1) onclick vs href

巧了我就是萌 提交于 2019-12-18 18:49:17
问题 Everybody knows that but I'll repeat the problem: <a href="#" onClick="history.go(-1)">Back</a> Will not work in WebKit based browsers (Chrome, Safari, Mxthon, etc.) Another approach (should work) that won't work is: <a href="#" onclick="javascript:window.history.back(-1);">Back</a> You could do this - works! (but that's showing JS in url hint) <a href="javascript:window.history.back(-1);">Back</a> To use JS in onclick event you could do this (works, but see comments below): <a onclick=

Change CSS Link Property onClick with Javascript/JQuery?

删除回忆录丶 提交于 2019-12-18 17:32:21
问题 So for example i have two links: <a onClick="doColorChange()">Link 1</a> <a onClick="doColorChange()">Link 2</a> I want it so that when I click Link 1, Link 1 changes to color blue to represent selected, Link 2 stays black. When the user clicks Link 2, then Link 2 changes color to blue and Link 1 changes color back to white. I currently have a default CSS property for links: a:link { color: #green; } I am unsure of the best way to handle the "doColorChange()" function. Is it best to create

onClick text change

随声附和 提交于 2019-12-18 16:58:47
问题 so I'm pretty new with html and need some help. I'm trying to make 3 buttons and each of them will change the text next to when you click on them. I am using the following code for each button: <a href="#" onClick="document.getElementById('past').innerHTML='---future---';"> When I click on the button the text will change in the text after the innerHTML=" ". The problem is that one I add to much text on the places ---future--- it won't load it anymore in the browser. The screen just won't