[英]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.