简体   繁体   English

您是否知道为什么我的代码无法正常工作,而单击时却无法获取数字?

[英]Do you have any idea why my code does not work and I can not get the numbers while clicking

I need help please If the next code. 我需要帮助,如果下一个代码。

I have two lines of 我有两行

Now I want my code in JQ when the user clicks One of which 现在,当用户单击其中之一时,我希望我的代码在JQ中

the Attribute of value will be printed to the screen. 值的属性将被打印到屏幕上。

Use the following code and I always undefined 使用以下代码,我总是不确定

Thank you very much for your help 非常感谢您的帮助

 $(this).click(function (){ var val = $('#223').attr("value"); alert (val) ; }) 
 <html> <head> <title>Page Title</title> <script src="https://code.jquery.com/jquery-3.1.1.js"></script> </head> <body> <p value="223">JQuery is </p> <p value="1.8">JQuery is </p> </body> </html> 

Use p instead of this 使用p代替this

$('p').click(function (){
     var val = $(this).attr("value");
   alert (val) ;
})

Example with your code:- 您的代码示例:-

 $('p').click(function (){ var val = $(this).attr("value"); alert (val) ; }) 
 <html> <head> <title>Page Title</title> <script src="https://code.jquery.com/jquery-3.1.1.js"></script> </head> <body> <p value="223">JQuery is </p> <p value="1.8">JQuery is </p> </body> </html> 

暂无
暂无

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

相关问题 我无法使这几行简单的代码正常工作,也不知道为什么 - I can't make these few simple line of code work correctly and have no idea why 我不知道为什么 ng-repeat 在我的代码中不起作用 - I have no idea why ng-repeat is not working in my code 我不明白为什么我的代码不起作用 - I can't figure why my code does not work 我无法让do while循环在javascript中工作 - I can not get my do while loop to work in javascript 为什么我必须重命名javascript文件才能使新功能正常工作 - Why do I have to rename my javascript file to get my new functions to work .get(0)vs .get(),我的JQuery意大利面条有效,我不知道为什么 - .get(0) vs .get(), My JQuery spaghetti works and I have no idea why Google将该文件用于Google可视化的位置在哪里?我可以将其本地化吗? 另外,是否有代码示例可以使IE中的量规工作? - Where does Google keep this file used for Google Visualization can I make it local to my site? Also, any examples of code to get gauges to work in IE? 为什么我需要在setTimeout中使用匿名函数才能使此代码生效? - Why do I need to have anonymous function in the setTimeout for this code to work? 为什么我必须刷新/重写我的代码以使其工作,同时尝试为特定用户保存状态以响应本机 - why i have to refresh/rewrite my code to make it work while trying to save the state for a specific user in react native 为什么必须重新加载页面才能使JS事件正常工作? - Why do I have to reload the page for my JS event to work?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM