doudong1117 2013-11-28 12:05
浏览 85
已采纳

如何使用链接在输入框之间导航?

How can I use a link to navigate between input boxes? So if I click the link it will focus on a specific input box. The solution can be with PHP, CSS, JavaScript or HTML.

So:

<a href='link1' class='link'>

Will navigate to/focus on

<input type='text' id='input1' class='input'>

And

<a href='link2' class='link'>

Will navigate to/focus on

<input type='text' id='input2' class='input'>

P.S: I may also use jQuery

  • 写回答

4条回答 默认 最新

  • duanmei1850 2013-11-28 12:09
    关注

    Use this:

    <a href='link1' class='link' onclick="document.getElementById('input1').focus(); return false;">link1</a>
    <input type='text' id='input1' class='input'>
    

    Define the onclick event for every link, with the input box id, according to example

    http://jsfiddle.net/jogesh_pi/xWXg6/

    Alternative - with JQuery:

    If you have link and input with the same classes and id like this :

    <a href='link1' class='link'>link1</a>
    <input type='text' id='input1' class='input'>
    
    <a href='link2' class='link'>link2</a>
    <input type='text' id='input2' class='input'>
    

    then use JQuery:

    $('.link').each(function(i, e){
        $(this).click(function(ev){
            ev.preventDefault();
            $('#input' + (i+1)).focus();
        });
    });
    

    Demo2: http://jsfiddle.net/jogesh_pi/zNqtB/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题