简体   繁体   中英

jquery click function to focus on textarea?

  function insertParamIntoField(anchor, param, field) {
       var query = anchor.search.substring(1, anchor.search.length).split('&');

       for(var i = 0, kv; i < query.length; i++) {
          kv = query[i].split('=', 2);
          if (kv[0] == param) {
             field.value = kv[1];
             return;
          }
       }
    }


$(function () {
    $("a.reply").click(function (e) {
       console.log("clicked");
       insertParamIntoField(this, "replyto", $("#inputField")[0]);
       e.preventDefault();
       return false; // prevent default action
    });
});

the html file

<textarea name="inputField" id="inputField" tabindex="1" rows="2" cols="40"></textarea>
    <a class ="reply"  href="home.php?replyto=username">reply</a>

this is my script what it deos it when the user clicks the reply link it prints @username, but i was wondering if i was at the button of the page and clicked reply, i want the focus to go back up on the textarea at the top? i was thinking along the lines of using #tags in html but is thier a way to do in jquery/javascript!! thanks

您可以调用$("#inputField").focus()

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM