onclick

jQuery click() on a nested div

空扰寡人 提交于 2019-12-07 05:37:25
问题 The code can probably explain this better than I can: <div class="wrapper"> <div class="inner1"></div> <div class="inner2"></div> </div> <script> $('div').click(function(){ var class_name = $(this).attr('class'); do_something(class_name); }); </script> When I click on the inner1 div, it runs the do_something() with both the inner1 div AND the wrapper . With the site being built, nested divs are going to happen a lot. Is there a dynamic way to fix this issue and only run the top level div (in

Dynamic Buttons and OnClickListener

落花浮王杯 提交于 2019-12-07 05:11:22
Say I have buttons that are created dynamically: for(int j = 0; j < spirits.length; j++){ Button imgBtn = new Button(v.getContext()); imgBtn.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); imgBtn.setMinimumWidth(100); imgBtn.setMinimumHeight(100); imgBtn.setId(j+1); imgBtn.setTag(spirits[j]); imgBtn.setText(spirits[j]); imgBtn.setOnClickListener(new SpiritsClickListener()); cabinet_layout.addView(imgBtn); } I want to change the text of the button every time it's pressed (On - Off) How can I reference the buttons within the OnClickListener class? in your

Click handler on <svg> element

跟風遠走 提交于 2019-12-07 03:48:12
问题 It seems that using a <svg:svg> </svg:svg> element does not render anything in Safari or Chrome, but using <svg> </svg> works fine. However, adding an onclick only works on <svg:svg> elements. What is the proper way to do this? This jsfiddle demonstrates the problem (compare Safari/Chrome to Firefox). 回答1: Okay, turns out that the first way of creating a SVG creates the onclick only on the drawn part. That means you can actually do something nice (maybe not useful in your case). In this

Android call onClick method without Clicking

£可爱£侵袭症+ 提交于 2019-12-07 03:42:08
问题 I want to use existing onClick method to make my program simpler. It consists of onClick method and other method: @Override public void onClick(View v) { switch(v.getId()){ case R.id.button1: .... break; } } void foo(){ .... onClick(????); } Is there any way to make it do the same behaviour like when i click it on the phone? 回答1: you can use View.performClick() reference 回答2: performClick() will play a sound just like if the user clicked on that view, therefore in most cases it's better to

Click GridView Find Selected Row

落爺英雄遲暮 提交于 2019-12-07 03:28:58
问题 I'm trying to take a GridView and get back the data from the row that was clicked. I've tried the code below and when I click the row I get back the selected index but when I look at the actual rows in the GridView they show empty. Not sure what I am missing. .ASP make my grid. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="True" CssClass="datatables" Width="100%" DataSourceID="SqlDataSource1" GridLines="None" ShowFooter="True" AllowSorting="True" onrowcreated="GridView1

Why does my ttk.Treeview click handler return the wrong item on tree.focus()?

别说谁变了你拦得住时间么 提交于 2019-12-07 03:16:52
问题 I have a simple script using a ttk.Treeview instance that I'm populating with the contents of a file system tree. I want to perform a certain operation when (leaf) items are clicked so I configured a handler like so: self.tree.tag_bind('#entry', '<1>', self.onClick) In the method onClick I am simply printing out the item that was clicked, like so: def onClick(self, event): item_id = str(self.tree.focus()) print 'Selected item was %s' % item_id item = self.tree.item(item_id) flag = '#another

React中的事件

僤鯓⒐⒋嵵緔 提交于 2019-12-07 02:22:16
一、事件方法 方法的声明与事件的写法(this指针的问题); 事件传参问题; 获取事件对象(传参与不传参); 键盘事件; 在元素上设置自定义的属性 import React from 'react'; class Event extends React.Component { constructor(props) { super(props); this.state = { msg:"我是消息" }; //第三种修改在构造函数里面 直接修改this指针的问题 this.btnClick3=this.btnClick3.bind(this) } //1.定义事件执行的方法 btnClick1(){ // console.log(this); //undefined 使用<button onClick={this.btnClick}>第一种获取数据的方式</button>,this为undefined,因为this不指当前事件的执行对象 console.log(this); //Event对象 使用<button onClick={this.btnClick.bind(this)}>第一种获取数据的方式</button>,.bind(this)指将this指针绑给方法 //通过this就可以操作当前组件 } //直接获取this指针 btnClick2=()=>{ console

How to confirm and call function with onclick

心不动则不痛 提交于 2019-12-07 01:58:36
问题 Can I call JavaScript function with return confirm(); in HTML onclick event or do I need to do function which contains confirmation and call to another function? <button onclick="return confirm('Are you sure?'); saveandsubmit(event);"></button> Thanks in advance. 回答1: Add if condition <button onclick="if(confirm('Are you sure?')) saveandsubmit(event);"></button> OR <button onclick="return confirm('Are you sure?')?saveandsubmit(event):'';"></button> 回答2: Try below : <button onclick="confirm(

Detect click on an image

孤街醉人 提交于 2019-12-07 01:25:04
问题 I am trying to load images dynamiaclly and displaying them as shown below var uploader = $('#<%=uploader.ClientId%>').plupload('getUploader'); uploader.bind('FileUploaded', function (up, file, res) { $('#<%=thumbs.ClientId%>').append("<div id=" + file.id + "> <a href='Uploads/" + document.getElementById("<%=currentDirectory.ClientId%>").value + "/" + file.name + "'/> <img src='Uploads/" + document.getElementById("<%=currentDirectory.ClientId%>").value + "/" + file.name + "' width='70' height=

React Hook

烂漫一生 提交于 2019-12-07 01:18:26
React Hook是React16.8.0引入的。使可以在不引入class的情况下,可以使用state和其他React特性。 hooks本质上是一些函数。 1. 为什么引入Hook? 1. hooks中的useEffect可以解决class中各逻辑在生命周期函数中管理混乱的问题。 2.hooks中的自定义Hook使得可以不修改组件的结构的基础上,灵活的复用组件逻辑。 3.class组件不能很好的压缩,并且热重载不稳定。不利于组件优化。使用Hook的函数组件不存在这些问题 2. Hook的规则 1. 只能在函数组件中使用hooks 类组件中无效。 2. 只能在函数最外层使用 不能用于if,for等语句中,也不能用于普通js函数中。因为ReactHook通过调用顺序确定对应的state等对应的hook方法。使用语句等会改变顺序。 3. 只能在以名字use开头的自定义Hook中使用 3. useState 接受一个参数作为初始值,参数可以是常量,也可以是一个返回值的函数。 初始值如果是一个函数,在初次渲染执行;如果是一个函数的执行,每次渲染都会执行 // 初始值是一个函数 const [count, setCount] = useState(function init(){......;return ..}) // 初始值是一个函数调用 const [count, setCount]