html 按钮 click事件无效,HTML / Javascript - 按钮需要两次点击才能执行点击事件(HTML/Javascript - Button takes two clicks to ...

HTML / Javascript - 按钮需要两次点击才能执行点击事件(HTML/Javascript - Button takes two clicks to execute click event)

但是,测试一个简单的切换显示,第一次切换显示需要两次点击。 之后它会在一个中完成。

#carousel{border:2px solid blue;

width:1280px;

height:720px;}

#p2{visibility:hidden;}

#p1{display:block;}

#btn{position:absolute;

top:2000px;}

Click

这是我的javascript:

function clickEvent(){

var p = document.getElementById("p1");

if(p.style.display == "block")

p.style.display = "none";

else

p.style.display = "block";

}

应该注意我没有使用jQuery,因为我发现的所有其他问题都与jQuery有关。

Testing out a simple toggle display, however, it takes two clicks to toggle the display the first time. Afterwards it does it in one.

#carousel{border:2px solid blue;

width:1280px;

height:720px;}

#p2{visibility:hidden;}

#p1{display:block;}

#btn{position:absolute;

top:2000px;}

pic1.jpg

pic2.jpg

Click

And here is my javascript:

function clickEvent(){

var p = document.getElementById("p1");

if(p.style.display == "block")

p.style.display = "none";

else

p.style.display = "block";

}

It should be noted I am using no jQuery, as all other questions I found about this were jQuery related.

原文:https://stackoverflow.com/questions/14103783

2020-02-10 18:02

满意答案

我在上面的评论中发布了对我之前小提琴的更新。 在进一步测试双击之后,我之前的小提琴仍然遇到了同样的问题。

单步执行后,初始显示值将返回""未block 。 我不确定为什么它没有取你在

部分设置的值,但如果你这样内联它:

pic1.jpg

只需单击一下按钮,它第一次就能正常工作。

这是我新的更新小提琴,展示了这一点。

我将更多地了解为什么你的样式在

部分,但是现在,这是一个快速(和半原始)修复。

希望这有帮助,祝你好运!

I have an update to my previous fiddle posted in my comment above. My previous fiddle still ran into the same problem after further testing of the double click.

After stepping through, the initial display value is coming back as "" not block. I'm not sure why its not taking your value you set in the

section but if you inline it like so:

pic1.jpg

it works correctly the first time with only one click of the button.

Here is my new updated fiddle demonstrating this.

I'm going to look more into why your styling in the

section but for now, here is a quick (and semi crude) fix.

Hope this helps and best of luck!

相关问答

这是我在网上找到的最佳答案。 它仍然不完美,因为它对标记为IsDefault或IsCancel的按钮没有帮助 protected override void OnPreviewMouseUp(MouseButtonEventArgs e)

{

base.OnPreviewMouseUp(e);

if (Mouse.Captured is Calendar || Mouse.Captured is System.Windows.Controls.Primitives.CalendarItem...

第一次点击,“saygoodbye”运行,发布“外部”警报,并建立点击处理程序。 第二次点击“saygoodbye”再次运行,发布“外部”,并建立另一个点击手。 这个“点击”事件然后由jQuery处理,jQuery目前有两个 “click”处理程序可以调用。 当你调用.click() ,你总是添加一个新的处理程序; 先前添加的处理程序不会被删除。 当您调用.off() ,它们将被删除,但只有在两个处理程序已连接时才会发生。 库(jQuery)维护处理程序列表并使用它自己的内部事件处理程序来实际处理...

在你的对象中, this是指对象本身的实例,所以你试图将一个click事件绑定到JavaScript对象,而不是DOM元素。 我猜你实际上想要这样的东西: var IOMaximizeButton = {

setup: function () {

$("#yourButton").click(function(){

console.log("maximize button was clicked!");

});

}

};

这是一个工作示例 。 In your...

这个问题是因为第一次点击执行chooseMap函数,然后附加事件处理程序。 第二次点击然后执行在这些事件处理程序中分配的代码。 要修复和改进您的代码,请删除内联onclick属性并使用jQuery来附加您的事件。 尝试这个:

World Map

没有任何意义,当您单击该按钮时尚未选择该文件,因此无法加载该文件。 它只是触发文件浏览器窗口。 $('#imgLoader').on('click', function(){

$('#results').html('I fired');

});

...

...

单击标签还将触发与其相关的表单元素上的单击事件。 如果删除label...

您应该真正修改您的代码以使用计时器。 当您滥用GUI线程并定期调用Application.DoEvents(); 点击只能在那个地方处理,这意味着你必须进入循环来处理事件。 这绝对不适合GUI编程。 请改用计时器。 以下是有关如何使用计时器定期调用方法的示例。 在您的情况下执行页面刷新。 You should really modify your code to use a timer. When you misuse the GUI thread and make periodic calls ...

如果我不得不猜测, $("#toggler_" + id)的html未设置为show 。 因此,第一次单击将设置为显示,第二次将加载数据。 在页面加载时确保切换器具有正确的html If I had to guess, $("#toggler_" + id)'s html is not set to show. So the first click will set it to show and the second will load the data. Make sure that the t...

我在上面的评论中发布了对我之前小提琴的更新。 在进一步测试双击之后,我之前的小提琴仍然遇到了同样的问题。 单步执行后,初始显示值将返回""未block 。 我不确定为什么它没有取你在

部分设置的值,但如果你这样内联它: pic1.jpg

只需单击一下按钮,它第一次就能正常工作。 这是我新的更新小提琴,展示了这一点。 我将更多地了解为什么你的样式在

部分,但是现...

如果将事件加载处理程序移到函数外部,它将按预期工作。 在这里,我只是删除了函数和内联脚本处理程序。 请注意,脚本需要在页面加载时运行,而不是之前运行 window.addEventListener('load', function() {

// Get the modal

var modal = document.getElementById('myModal');

// Get the button that opens the modal

var btn = d...

相关文章

作者:李丽媛 联系方式:lly219#gmail.com 日 期:2010-2-26 前言

...

作者:李丽媛 联系方式:lly219#gmail.com 日 期:2010-2-26 前言

...

JavaScript 的事件是以一种流的形式存在的,一个事件会有多个元素同时响应。有时候这不是我们想要

...

各位大虾晚上好,我有个问题想请教你们,我想美化html的file外观,但貌似现在还不能用css直接设计

...

1>页面中直接在script标签中书写 <html><head><

...

一.DisMax 1.tie:query and init param for tiebreaker

...

原文来自:http://html6game.com/thread-1023-1-1.shtml 转自:

...

我想两次replace,分别把&#039;和&#034;替换为单引号和双引号,但在前台

...

<script type=“javascript”> function test(){

...

给一个div绑定一个click事件,如果这个div没有内容,在一般浏览器下都没有问题,在IE8下点击的

...

最新问答

List lc = driver.findElements(By.cssSelector("table[id*='filter']")); for (WebElement row : lc) { List images = row.findElements(By.tagName("img")); for (WebElement image : images) { image.click(); } } List

我没有任何问题,但我能够通过启用我的弹出窗口拦截器(我使用更好的弹出窗口阻止程序 - Chrome网上应用店 )来重现你在运行Chrome 21.0.1180.89的Windows 7上遇到的问题。 如果您使用弹出窗口阻止程序,请尝试为jsfiddle /您正在使用的站点禁用它。 I didn't have any issues with it, but I was able to reproduce the problem you were having on Windows 7 runnin

opencv已经有开源的人脸识别的代码了,只需要安装一下,有训练好的关于人脸的xml文件,然后根据这两个xml文件,输入一张带有人脸的图片进行检测就好了。参考网址:http://www.cnblogs.com/mengdd/archive/2012/08/01/2619043.html 这里说的更详细一些。matlab是专门针对图像处理的,不过一般的用matlab实现的,用opencv也都可以做的到。有些时候将matlab代码转为opencv还是需要一定时间和一定功底的

您需要使用ProximitySensor来检测手机屏幕何时被覆盖。 这是一个例子: 在android中使用接近传感器 You need to use ProximitySensor to detect when the phone screen is covered. Here is an example: Using proximity sensor in android

我认为找到这个的最简单方法是搜索ProjectName列。 它似乎包含层次结构信息: select c.* from content c where ProjectName+' ' like '%Project 1 %' 额外的空间是确保Project 1与Project 10不匹配。 I found the way to solve. But the actual solution is given by Jayvee. Sorry I didnt know the method it ca

弄清楚了! 它被链接到: searchText: 'Search for a member...', 这将自动填充搜索栏的内容,并尝试根据该搜索词找到用户。 删除此属性解决了这个问题。 Figured it out! It was linked to: searchText: 'Search for a member...', This will autofill the search bar with content and will attempt to find the user

错误2245也可能是密码历史记录问题。 新密码是最近使用的密码吗? 编辑:看起来这个功能在Server 2003 SP 2之后破了。我在使用文档中的示例从C ++调用函数时遇到了同样的错误。 您可能需要使用NetUserSetInfo。 Error 2245 could also be a password history problem. Is the new password one that was used in the recent past? Edit: It looks like

我在网上搜索了很多,为我的问题找到答案。 我花了很多时间,所以我在这里贴出来帮助别人。 为了使GLEW与MinGW一起工作,您应该从GLEW网站下载源代码并放置 来自MinGW \ bin的gcc.exe 来自MinGW32 \ mingw32 \ bin的ar.exe 到GLEWs源文件夹并在该文件夹中创建并运行.bat,如下所示: gcc -DGLEW_NO_GLU -O2 -Wall -W -Iinclude -DGLEW_BUILD -o src/glew.o -c src/glew.

使用模板成员函数时,您需要使用template关键字,如下所示: my_postoffice.template get_postbox() 和 po.template get_postbox() cf here: http : //ideone.com/W0owY1代码和这里: 我在哪里以及为什么要放置“template”和“typename”关键字? 有关何时使用模板关键字的确切说明 You need to use the template keyword when using

你不能,至少在Devel :: REPL调用Data :: Dump :: Streamer的情况下。 DDS将始终编码不在\ x20- \ x7e范围内的任何字符。 您可以修改DDS以选择其他方式。 After reading the source of DDS, I came up with this patch based on the Perl Monks code: $ cat quote.rc { no warnings 'redefine'; sub Data::D

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值