Home > front end >  JQuery in $(this) returns undefined
JQuery in $(this) returns undefined

Time:10-26

$(this) in jQuery return is undefined, with the index () method to obtain the index of the whole of 1, is what circumstance?
show_tab () method
Var MTHTML="& lt; Tr> ";
For (var I=0; i Var="" tt;
Tt="& lt; Td style=\ "width: 120 px; Height: 40 px; text-align:center; font-size:12px; \ "onclick=" show_tab (); \ "& gt;";
Tt +=mm + "in the first" + (I + 1) + "weeks & lt;/td>
MTHTML +=tt;
}
MTHTML +="& lt;/tr> ";
//the console. The log (cont);
//the document. The write (cont);
$(' # ll '). The empty (), append (MTHTML);

Here is in the baidu to find all kinds of writing, are not

Show_tab=function () {
//var shen=$(this);
//var aa=$(this). Prop ();
//varrs=$(" # ll td "). Eq (index). The HTML ();
//varrs=$(" li "). Eq. (index) get (0). The attr (" value ");
//$(this). The CSS (" color ", "blue"). The siblings (). The CSS (" color ", "");
//$(" # ll tr td "). The CSS (" color ", "blue");
//var wwe=$# (rr);
//var value=https://bbs.csdn.net/topics/$(obj). Parents (" tr "). The children (" td "). Eq. (1) find (" input: first "). Val ();
//var wwe=parseInt ($(this). The HTML (). The substr (3, 1));
//alert (wwe);
//var aa=$(this). The parent (" td "). The HTML ();
Var aa=$(this). The index (" td ");
//var aa=$(this). The children (" # ll td "). The index ();
//var aa=$(" # ll tr td "). The index (this);
//var aa=$(" # ll tr td "). The index (this);

//$(obj). The parent (.), find (" td "). RemoveClass (" tdactive ");
//the console. The log ($(this). Parents (" tr "). Attr (' width '));
The console. The log (aa);
}



CodePudding user response:

The onclick=\ "show_tab. Call (this); \ "& gt;;

Or
The onclick=\ "show_tab (this); \ "& gt;;

Show_tab=function (thisObj) {
Var shen=$(thisObj);

CodePudding user response:

 
$(' # ll '). The empty ()
For (var I=0; i Let $td=$(` & lt; Td style="width: 120 px; Height: 40 px; text-align:center; font-size:12px;"> ${mm} on the first ${I + 1} weeks & lt;/td> `)
$td) on (' click 'show_tab);
$(' # ll '). Append ($td)
$(' # ll '). Append ($(' & lt; Br/& gt; '))
}

CodePudding user response:

 onclick=\ "show_tab (ele); \ "& gt;; 
Show_tab=function (ele) {
Var shen=$(ele);
}

CodePudding user response:

For dynamically generated HTML tags, if you want to use jquery to get to it, can from $(' body # ll ') to get to him
  • Related