我試圖在每次點擊它時更改div
中的文本。我嘗試了以下,但它不工作:每次在div上使用.append()和click()時
<script>
$(document).ready(function() {
//alert('hi');
$('div').css('cursor','pointer')
$('div').append('hi')
$('div').click(function() {
if ($(this).html('hi') {
$(this).html('how r u');
}
if ($(this).html('how r u')) {
$(this).html('hi');
}
)
//$(this).html('how r u');
})
})
</script>
任何人都可以幫助我嗎?
在此先感謝
你的示例代碼有幾個語法錯誤 - 在你的'$(「div」)之後缺少大括號,單擊(fn)'和腳本末尾的額外右括號和大括號。 – 2012-03-22 13:37:43
你的意思是切換?像 '$(「div」)。toggle(function(){$(this).html(「Hi」)},function(){$(this).html(「你好嗎?」)}); $(「div」)。trigger(「click」);' – 2012-03-22 13:46:06