I wrote this simple code to understand why if I click the "click me" text for the second time JQuery does not display the "second" text.
<div id="clickme">Click me</div>
<div id="sometext">This is text ZERO</div>
<script type="text/javascript">
$(document).ready(function($) {
$("#clickme").click(function(){
if (a == 1) {
$( #sometext ).replaceWith( <div id="sometext">This is text TWO</div> );
}
else {
$( #sometext ).replaceWith( <div id="sometext">This is text ONE</div> );
var a = 1;
}
});
});
</script>
我期望以下行为:
- Page is loaded and the text This is text ZERO is displayed
- I click the link the first time and JQuery displays This is text ONE
- I click the link a second time and jQuery displays This is text TWO
相反,第3点没有处理,或者至少没有显示案文。 为什么?