在 html span 和按钮之间建立连接



如何在 html span 和按钮之间建立连接 - 我希望当我在跨度聚焦时按回车键时,html 按钮会点击而不是另一个(就像我现在发生的那样)谢谢!

像这样...

var str='<a href="https://api.jquery.com/click/" >jquery's .click() function </a><br><br><a href="https://api.jquery.com/html/" >jquery's .html() function </a><br><br><a href="https://api.jquery.com/focus/" >jquery's .focus() function </a><br><br> <a href="https://api.jquery.com/keyup/" >jquery's .keyup() function </a><br><br>';
$('#btn').click(function(){
  $('#myspan').html(str);
});
// detect enter keypress in an input field
$('#field').keyup(function(e){
    if (e.keyCode == 13) { 
        $('#myspan').html(str);
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span id="myspan"></span><br>
<input type="button" value="Push me...." id="btn"/>
<input type="text" id="field" placeholder="or..type in me and press enter..." id="btn" size="55"/>

最新更新