1

Hey guys I'm trying to make it so when you click on the existing a href= it will paste the inner text to the textarea. Though of course if click that the a href it'll lead to link so i made it so it'll take out the href. So far I have this code

$(function(){
$(".username a").removeAttr("href").css("cursor","pointer");
var $paste = $('div.post h4 .username a span');
  $paste.click('')
});

Ok I guess thats a good start lol. Problem to me is, I don't know how to add onClick="" or whatever to make the function work on click ya know? or would .click work in general. of course i would need a function in the .click area. I don't know what to place in there to create what text is inside the a tag... Can someone help me, if you use .append or or anything can you also give an explanation, I'm trying to learn as I go.

4

2 回答 2

2
$(function(){
    $('.username a').click(function(){ return false; });
    $('.username a').one('click', function(e){
             //e is short for event
        e.preventDefault(); //will no longer follow through
        //You want to append the text of the anchor link into the textarea.

        var innerTxt = $(this).text();
        //need to trim whitespace from the string
        innerTxt = $.trim(innerTxt);

        var $obj= $('textarea'); //replace this with textarea selector
        $obj.val(
           $obj.val()+'\n@'+innerTxt
        );               
    });
});​
于 2012-10-19T23:53:33.697 回答
0

Try this

$(".username a").click(function(e){
    //DO Wathever you want here 
    e.preventDefault(); 
})
于 2012-10-19T23:54:54.760 回答