Why doesn't my external jQuery click() event work in Jade?

[亡魂溺海] 提交于 2019-12-13 06:01:38

问题


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

And here is a jade file:

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

回答1:


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

Am I going crazy? jQuery .click() doesn't seem to work



来源:https://stackoverflow.com/questions/19964609/why-doesnt-my-external-jquery-click-event-work-in-jade

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!