开发者

How can I convert text into link using Jquery and assign a function using Jquery?

How can I convert text into link using jQuery and assign a function? I have a table and I want to convert table’s last row’s first cell text into link and 开发者_开发问答assign onclick function “DisplayDetails()”.

My table name is “ScoreCardDataCurrentTable”.


$("#ScoreCardDataCurrentTable").children("tr:last").children("td:first").click(function(){
   DisplayDetails()
});

This code will set call DisplayDetails() when the first cell of the last row in the table is clicked. If you want the text itself to call the function you will have to tell us what the text is contained in.

it may be simpler just to use a link with an id and use CSS to style it how you like.


Try:

var cell = $('#ScoreCardDataCurrentTable tr:last td:first');

var text = $(cell).text();

var link = $('<a />').text(text).bind('click', function(){
    // your code here
    DisplayDetails();

});

$(cell).html(link);

// I'm assuming that your table has an ID of ScoreCardDataCurrentTable


var myCell = $('#mytable>tr:last>td:first');
var myContents = myCell.html();

//We do not use onclick attribute cause it may bring hell to our known world
var pseudoLink = $('<a>'+myContents+'</a>').click( function() {
  //Stuff here
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜