简体   繁体   English

Javascript-jQuery-click(function()

[英]Javascript - Jquery - click(function()

Can someone tell me what is wrong with this javascript ? 有人可以告诉我此javascript有什么问题吗?

      $("#parent-project").attr("data-id").click(function(){ 
       //some code...
      }

The console output is: 控制台输出为:

Cannot read property 'click' of undefined 无法读取未定义的属性“单击”

Using attr() will return a string value to which a click handler cannot be attached. 使用attr()将返回无法附加点击处理程序的字符串值。 I imagine you wanted 我想你想要

$("#parent-project[data-id]").click(function(){ 
       //some code...
      }

In which [] is notation for attribute 其中[]是属性的符号

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM