English 中文(简体)
e. 预防 Default () 似乎不像它应该表现的那样
原标题:e.preventDefault() doesn t seem to act like it is supposed to

我有一个小部件可以显示这个页面的侧边栏上的天气。 http://jbm.utad.pt/testes/equipa.php

文件一准备好,AJAX就会拍摄一个城市名称,

<div id="exibe-tempo"></div>

手风琴用来显示预报和选择不同的城市, 问题来了。 代码在这里发布的时间有点长, 所以我做了: < a href="http://jsfiddle. net/jZjQy/1/" rel="nofollow noreferrer" >http://jsfiddle. net/jZjQy/1/

它拥有内部设备a.php的jQuery 和进程a-tempo.php返回的标记。

如果我在新城市点击... 它不会按原计划运行(重新更新 div "exibe-tempo" ) 。

我真的不知道该怎么调试这个... 帮什么忙吗?

最佳回答

我再次检查了您的页面, 并可能发现错误。 您会以动态方式添加包含城市的链接。 但是点击上的绑定会出现在页面加载事件上 。 因此您必须应用一个现场听众来倾听这样的事件 :

$(document).on( click , .cidade ,function(event){
event.preventDefault();
问题回答

我查了你的网站,我想是这样的,告诉我它是否适合你

您点击城市的代码定义如下:

    $("#cidades").click(function(event){
  event.preventDefault ? event.preventDefault() :event.returnValue = false;
      ..... });

但你的链接被定义为,

    <a href="Penafiel" class="cidade">Penafiel</a>

改变你的jquery到,

    $(".cidade").click(function(event){
  event.preventDefault ? event.preventDefault() :event.returnValue = false;
      ..... });

这样, 您就可以将点击函数绑绑在每一个标签上, 而不是周围的 UL 。 我尝试了您网站的上述代码, 并且它起作用了 。

因为我无法张贴图像- & gt; < a href="https://i.static.net/FeRnb.png" rel=“ no follow” >https://i.static.net/FeRnb.png





相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签