为什么我的外部jQuery click()事件在Jade中不起作用? [英] Why doesn't my external jQuery click() event work in Jade?

查看:130
本文介绍了为什么我的外部jQuery click()事件在Jade中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某些原因,尽管单击主体时它确实起作用,但单击任何元素时都无法使该单击事件起作用.我知道ID已正确分配,因为CSS也可以正常工作.这是JS:

For some reason I can't get this click event to work when clicking any element, although it does work when I click the body. I know the ID is correctly assigned because the CSS also works fine. Here's the JS:

$('h2').click(function() {
  alert( "h2 clicked." );
});//DOES NOT WORK

$('#whatever').click(function() {
  alert( "Whatever clicked." );
});//DOES NOT WORK

/*
$('body').click(function() {
  alert( "Body clicked." );
});
*/ //THIS WORKS WHEN UNCOMMENTED 

console.log('thank you!'); //THIS WORKS

这是一个玉文件:

extends ../layout

block content
  h2= post.title
  #whatever
   p= post.body
  span= post.created.toGMTString()
  p by #{post.author.fullname}
  br
  br
  div
    a(href="/post/edit/" + post.id) Edit
    | |
    a(href="/post/remove/" + post.id) Delete
  .comments
    ul
      each comment in comments
        li
          p.text= comment.text
          p.author= comment.author
    if session.isLoggedIn
      form(method='post', action="/post/comment/" + post.id)
        textarea(name='text')
        input(type='submit', value='Save')

这是涉及的另一个玉器文件:

and here is the other jade file involved:

html5
html
  head
    title= pageTitle
    link(rel='stylesheet', type='text/css', href='/stylesheets/styles.css')
    //script(type='text/javascript', src='/js/jquery-1.10.2.min.js')
    script(type='text/javascript', src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js')
    script(type='text/javascript', src='/js/scriptures.js')

 body
    header
      h1= pageTitle
    a(href="/") Home
    section.login
      ul
        if session.isLoggedIn
          li
            a(href="/logout") Logout
        else
          li
            a(href="/login") Login
          li
            a(href="/signup") Create Account
    section.content
      block content

推荐答案

$(document).ready(function(){$('#whatever').click(function(){ alert(无论单击什么."); }); });

$(document).ready(function(){ $('#whatever').click(function() { alert( "Whatever clicked." ); }); });

我疯了吗? jQuery .click()似乎不起作用

这篇关于为什么我的外部jQuery click()事件在Jade中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆