开发者

jquery click function to focus on textarea?

开发者 https://www.devze.com 2023-01-16 14:21 出处:网络
function insertParamIntoField(anchor, param, field) { var query = anchor.search.substring(1, anchor.search.length).split(\'&\');
  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


You can call $("#inputField").focus().

0

精彩评论

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