<分区>
标签 javascript jquery html css
我有一个按钮,我希望当我点击它时添加一个输入,然后按下回车输入按钮或其他东西。
<button>add tag</button>
<input type="text" name="" placeholder="tag">
$(document).ready(function () {
$('button').click(function () {
$("button").before("input");
});
});
最佳答案
试试这个
$(document).ready(function() {
$('button').click(function() {
$("body").before("input");
});
$("input").keyup(function(e) {
if (e.keyCode == 13)
$(this).attr("type", "button");
$(this).val('button')
})
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button>add tag</button>
<input type="text" name="" placeholder="tag"><button>add tag</button>
<input type="text" name="" placeholder="tag"><button>add tag</button>
<input type="text" name="" placeholder="tag"><button>add tag</button>
<input type="text" name="" placeholder="tag"><button>add tag</button>
<input type="text" name="" placeholder="tag"><button>add tag</button>
<input type="text" name="" placeholder="tag">
关于JavaScript 更改元素类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54842240/