我有这样的html:
<html>
<input type='button' name='button1' id='button1'>
<input type='button' name='button2' id='button2'>
</html>
我想要做什么,当用户单击 button2 时,它应该删除 button1 元素并在其位置显示一条消息。 button2 点击事件后,它看起来像这样。
<html>
Button1 Removed
<input type='button' name='button2' id='button2'>
</html>
最佳答案
如果你使用jquery,你可以这样做:
$('#button2').click(function() {
$('#button1').replaceWith('Button1 Removed')
});
关于javascript - 如何使用特定 id 删除元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5829138/