ios下Safari无法触发click事件的处理

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Jacksun_huang/article/details/87967046
<!DOCTYPE html>
<html>
<head>
<title>122</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no"> </head>
<body>
<div>
adfafasdfasdfasdfasfdasdf<br/>
adfafasdfasdfasdfasfdasdf<br/>
adfafasdfasdfasdfasfdasdf<br/>
adfafasdfasdfasdfasfdasdf<br/>
adfafasdfasdfasdfasfdasdf<br/>
adfafasdfasdfasdfasfdasdf<br/>
adfafasdfasdfasdfasfdasdf<br/>
adfafasdfasdfasdfasfdasdf<br/>
adfafasdfasdfasdfasfdasdf<br/>
adfafasdfasdfasdfasfdasdf<br/>
</div>
<div>
<img src="__IMG__/indexbanner.png" alt=""/>
</div>
<script src="__JS__/jquery-1.11.1.min.js"></script>
<script> $(function(){ $('body').on("click", function(e){ alert("click"); }); }) </script>
</body>
</html>

提问:点击在文字上和点击在图片上是否都会弹出“click”呢?

呵呵呵呵呵呵,结果是只有第二个img的点击能正确触发click,点击div里的文字完全没效果。

解决办法就是绑定到  “touchend” 事件。。。

这个bug只有在ios的Safari下才能出现,桌面端、android端都没有问题,苹果真是傲娇啊。。

ps:移动端的点击处理还是得尽量用touch类的事件。。click坑太多了。

 

展开阅读全文

自定义控件无法触发click事件

04-30

using System;rnusing System.Collections.Generic;rnusing System.ComponentModel;rnusing System.Linq;rnusing System.Text;rnusing System.Web;rnusing System.Web.UI;rnusing System.Web.UI.WebControls;rnrnnamespace ServerControl1rnrn [DefaultProperty("Text")]rn [ToolboxData("<0:ServerControl1 runat=server>")]rn public class ServerControl1 : WebControl,INamingContainer,IPostBackEventHandlerrn rn TextBox username;rn TextBox password;rn Button btnlogin;rn CheckBox cbxRemember;rn Table t;rnrn /// rn /// 创建控件的方法rn /// rn protected override void OnInit(EventArgs e)rn rn btnlogin = new Button();rn btnlogin.ID = "btn1";rn btnlogin.Text = "登陆";rn btnlogin.Click += new EventHandler(btnlogin_Click);rn base.OnInit(e);rn rn rn protected override void CreateChildControls()rn rn rn rn base.CreateChildControls();rn t = new Table();rn TableRow tr1 = new TableRow();rn TableCell cell11 = new TableCell();rn TableCell cell12 = new TableCell();rn tr1.Controls.Add(cell11);rn tr1.Controls.Add(cell12);rn cell11.Text = "用户名";rn username = new TextBox();rn cell12.Controls.Add(username);rn TableRow tr2 = new TableRow();rn TableCell cell21 = new TableCell();rn TableCell cell22 = new TableCell();rn cell21.Text = "密码:";rn tr2.Controls.Add(cell21);rn password = new TextBox();rn cell22.Controls.Add(password);rn tr2.Controls.Add(cell22);rnrn TableRow tr3 = new TableRow();rn TableCell cell31 = new TableCell();rn TableCell cell32 = new TableCell();rn cbxRemember = new CheckBox();rn cbxRemember.Text = "记住cookies";rn cell31.Controls.Add(cbxRemember);rn tr3.Controls.Add(cell31);rnrn rn cell32.Controls.Add(btnlogin);rn tr3.Controls.Add(cell32);rn t.Controls.Add(tr1);rn t.Controls.Add(tr2);rn t.Controls.Add(tr3);rn rnrn void btnlogin_Click(object sender, EventArgs e)///此位置无法触发rn rn rn this.onLogin(EventArgs.Empty);rn rnrn public string UserNamern rn getrn rn return this.username.Text;rn rn setrn rn this.username.Text = value;rn rn rn public string PassWordrn rn get rn rn return this.password.Text;rn rn setrn rn this.password.Text = value;rn rn rnrn public event EventHandler Login;rnrn //触发事件的方法rn protected void onLogin(EventArgs e)rn rn if (this.Login != null)rn rn this.Login(this, e);rn rn rnrn //protected override void EnsureChildControls()rn //rn // if (!ChildControlsCreated)rn // rn // this.BuildControls();rn // this.ChildControlsCreated = true;rn // rn rn // base.EnsureChildControls();rn rn //rn protected override void RenderContents(HtmlTextWriter output)rn rn //this.EnsureChildControls();rn t.RenderControl(output);rn rnrn #region IPostBackEventHandler 成员rnrn public void RaisePostBackEvent(string eventArgument)rn rn Login(this, EventArgs.Empty);rn rnrn #endregionrn rnrn 论坛

没有更多推荐了,返回首页