I am creating Jquery Tabs dynamically by passing in a viewName parameter. I am trying to figure out how to use this
to trigger another function based on the id
of the dynamically created Tab.
Here is function that creates the Tabs and assigneds them an ID
and Name dynamically.
function SetImportedView(viewName, scriptValue) {
/* put the values we received in parameters into create view tabs*/
$('<li id="' + viewName + '">' + '<a href="' + '#tabs-1' + '"</a>' + viewName + '</li>').insertBefore('#new');
}
I need to trigger a another function that is specific to the ID
of the Tab that is clicked.
something like this:
$(this.tab).click(function() {
doSomething
}
What's with this
function SetImportedView(viewName, scriptValue) {
/* put the values we received in parameters into create view tabs*/
$('<li id="' + viewName + '">' + '<a href="' + '#tabs-1' + '"</a>' + viewName + '</li>')
.on( 'click', 'a' function( ev ) {
// link in li clicked
} )
.insertBefore('#new');
}
ok, you mean something like this?!?!
$( 'li' ).on( 'click', 'a', function( ev ) {
var tabID = $( this ).parent().attr('id');
// do something here with your tabID
} );
只需在您的“ a”标签上放置一个onclick即可,使其呈现如下所示:
<a href="javascript:void(0);" onclick="return myFunction();">TAB #1</a>
Solved...
$('#tabs ul li a').click(function() {
console.log($(this).attr('id'));
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.