我想通過使用javascript在jQuery中切換某些特效,請問這段代碼是否正確?什麼是最簡單的解決方案?如何使用javascript切換某些jQuery效果
P.s.不要說 「使用.toggle()」,目前它導致它最大限度地減少該段
HTML
<!--This first line calls in jquery-->
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<p>Hello all</p>
CSS
p {
color: red;
background-color: lightblue;
border-radius: 5px;
height: 50px
}
JQUERY錯誤/ JAVASCRIPT
var num = 0;
$(document).ready(function() {
$("p").click(
if (num == 0) {
var num == 1;
} else {
var num == 0;);
$("p").click(function() {
if (num == 1) {
$(this).animate({
color: "black",
backgroundColor: "white",
fontFamily: "arial",
fontSize: "20px",
fontFamily: "serif"
}, 500);
} else {
$(this).animate({
color: "red",
backgroundColor: "lightblue",
borderRadius: "5px",
height: "50px",
}, 500);
});
});
謝謝大家你的時間,我真的很感激。
這是一個很好的答案!但我也想知道爲什麼我的代碼不起作用? @adeneo – marcnetz 2014-11-08 18:55:17
你的代碼不起作用,因爲它充滿了語法錯誤!你不能只寫'$('p')。click(if(this)that)'< - 這是一個語法錯誤 – adeneo 2014-11-08 19:59:07