onclick

Javascript 事件监听

拈花ヽ惹草 提交于 2019-11-30 12:25:44
1.addEventListener() 基本用法 语法:node.addEventListener(事件名称,回调函数,是否使用事件捕获传递) 注意:使用匿名的回调函数后面会无法移除 <script> var ul = document.querySelector('#ul') ul.addEventListener('click',function(){ console.log('点击了ul') }) </script> 第三个参数: 这个参数用来描述是否使用事件捕获传递,默认为false 事件传递方式就两种,一种是冒泡(完全由内到外),另一种是捕获(由外到内),即默认为冒泡传递 实例:3个dom元素都绑定了点击事件 <ul id="ul" onclick="test('ul')"> <li id="li"> <p onclick="test('p')">11111</p> </li> </ul> <script> function test(msg){ console.log(msg) } var li = document.querySelector('#li') li.addEventListener('click',function(){ console.log('点击了li') },false) // 默认false 冒泡传递 </script> 此时点击li标签

Add onclick and onmouseover to canvas element

隐身守侯 提交于 2019-11-30 12:11:47
I want to add an onclick , onmouseover and an onmouseout events to individual shapes in a canvas element. I have tried doing this with SVG in different ways and found no single method will work in all the major browsers. Maybe, is there a simple way to add an onclick and probably other events to canvas shapes? Can someone please show me how to add an onclick ? Here is my code: canvas { background:gainsboro; border:10px ridge green; } <canvas id="Canvas1"></canvas> var c=document.getElementById("Canvas1"); var ctx=c.getContext("2d"); ctx.fillStyle="blue"; ctx.fillRect(10,10,60,60); var ctx=c

javascript passing text input to a onclick handler

浪尽此生 提交于 2019-11-30 11:57:23
问题 Lets say I have a form as below. How do I pass the value in the textbox named "configname" to the onclick function handler?? <form id="loadconfigform"> Config Name: <input type="text" name="configname" /> <input type="button" value="Submit" onclick="onLoadConfigPress(configname)" /> </form> 回答1: Give an id to input field: <input type="text" id="configname" name="configname" /> Now modify click handler as follows: <input type="button" value="Submit" onclick="onLoadConfigPress(document

d3.js 共享交换平台demo

↘锁芯ラ 提交于 2019-11-30 11:55:10
今天在群里遇到一张图 遂来玩一玩,先来上图!! 点击相应按钮,开关线路,此项目的重点是计算相应图形的位置,由于是个性化项目就没有封装布局。好了直接上代码。 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>$Title$</title> <script src="https://d3js.org/d3.v4.min.js"></script> <style> .container { padding: 0 100px; } button { width: 100px; } .rect { stroke: #406DA7; fill: #6693CC; stroke-width: 2; } .center { stroke: #FF3336; fill: #FF7F7E; stroke-width: 2; } .text { fill: #ffffff; text-anchor: middle; font-size: 30px; shape-rendering: crispEdges; } .circle { fill: #ffffff; stroke: #FF7F7E; stroke-width: 2; } .cha { fill: #ffffff; stroke: #FF7F7E;

jQuery input button click event listener

不问归期 提交于 2019-11-30 10:56:59
问题 Brand new to jQuery. I was trying to set up an event listener for the following control on my page which when clicked would display an alert: <input type="button" id="filter" name="filter" value="Filter" /> But it didn't work. $("#filter").button().click(function(){...}); How do you create an event listener for a input button control with jQuery? 回答1: First thing first, button() is a jQuery ui function to create a button widget which has nothing to do with jQuery core, it just styles the

Android beginner: Touch events in android gridview

a 夏天 提交于 2019-11-30 10:24:00
I am using the following code to do things with gridview(slightly modified from http://developer.android.com/resources/tutorials/views/hello-gridview.html ). I want to replace the onClicklistener and the onClick() method with their "touch" equivalents i.e. touchlistener and onTouch() so that when i touch an element in the gridview the image of the element changes and a double touch on the same element takes it back to the orginal state. How do I do this? I can't get my code to do this. The clicklistener works to some extent but the touch isn't. Please help. public class ImageAdapter extends

js使用案例

老子叫甜甜 提交于 2019-11-30 10:09:46
1、判断是否微信浏览器 function is_weixn(){ var ua = navigator.userAgent.toLowerCase(); if(ua.match(/MicroMessenger/i)=="micromessenger") { return true; } else { return false; } } if( is_weixn() ) { document.write("微信浏览器") } else { document.write("其他浏览器") } 2、判断是移动端浏览器还是PC浏览器 if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { document.write("移动") } else { document.write("PC") } 3、创建一个菜单搜索 //html部分 <div class="row"> <div class="left" style="background-color:#bbb;"> <h2>菜单</h2> <input type="text" id="mySearch" onkeyup="myFunction()" placeholder="搜索.." title=

Javascript: Close Popup, Open New Window & Redirect

99封情书 提交于 2019-11-30 10:05:42
I would like to close the current popup, open a new window (tab) and redirect to a specific link. This works extremly easy with my <a> links. I simply add "target="_blank"" and it works just fine (it doesnt close the pop up actually, but minimizes it and thats fine too). Since I am using some buttons with a onclick function, I want to implent the "target="_blank" in the button somehow... The button looks like this at the moment: <input type="button" onclick="parent.window.opener.location='http://google.com'; window.close();"> This works, but the problem is that it redirects in the parent

Click button on website then scrape web page

a 夏天 提交于 2019-11-30 10:04:47
I have a website I would like to click a button on then scrape the website using python the html code between the button is: <span id="exchange-testing" class="exchange-input nav-link" data track="&lid=testing&lpos=site_settings" data-value="testing">Testing</span> Is this possible? I am able to scrape all the data I need from the page but I need to click the button first. Any help would be appreciated Basically, you have two options: high-level approach : automate a real browser using selenium or, in other words, make the browser repeat all the user actions needed to get to the page with the

Using jQuery to 'click' a li element

拜拜、爱过 提交于 2019-11-30 08:48:05
I have a <ul> element that dynamically generates the <li> elements and simply want to run a onclick event <ul id="results"> <li class="device_result searchterm" data-url="apple-iphone-5s"> <a href="#"> Apple iPhone 5s </a> </li> <li class="device_result searchterm" data-url="apple-iphone-5c"> <a href="#"> Apple iPhone 5s </a> </li> </ul> I've got the following jQuery in a $(document).ready block but it doesn't seem to work - any ideas what I'm doing wrong? $("li .searchterm").click(function() { console.log("testing"); }); if you add dinamically put the click on the list but select the items: $