我想弄清楚如何在不刷新浏览器的情况下同时点击我的按钮。我注意到,如果我点击其中一个按钮的工作,并使用.replaceWith
替换它的新值,但是当我点击另一个按钮时,它不会给我另一个值。使用replaceWith同时单击按钮而不刷新浏览器
代码:
<body>
<input type = "button" id = "bt1" value = "See my Full Name :)">
<input type = "button" id = "bt2" value = "See my Nickname :)">
<div>
<div class = "name">See my name</div>
</div>
<script>
$(document).ready(function()
{
$("#bt1").click
(
function()
{
$("div.name").replaceWith("<div>John Francis</div>");
alert("Your full name is John Francis");
}
);
$("#bt2").click
(
function()
{
$("div.name").replaceWith("<div>Francis</div>");
alert("Your nickname is Francis");
}
);
});
</script>
为什么我应该使用'.text'而不是'.replaceWith'有没有使用'.replaceWith'的方法? – Francisunoxx
我会投票给你的第二个小提琴。大。 – Atula