如何在html span和button之间建立连接 - 我希望当我在跨度处于焦点时按Enter键时,html按钮将单击而不是另一个(现在发生在我身上) 谢谢!
答案 0 :(得分:0)
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);
}
});
&#13;
<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"/>
&#13;