【发布时间】:2014-12-05 01:56:03
【问题描述】:
我是 js/jQuery 新手,如果这是一个重复的问题,请原谅我! 我正在尝试建立比萨订购网站,通过单击浇头的图像按钮将浇头放置在面团图像上或将其删除。所有浇头必须有 3 个阶段,左侧、整体和右侧。然后我必须通过 ajax/php 将选定的浇头发布到服务器。
我已经测试了 ajax/php 模块及其工作。但是,我被困在 jQuery 部分,这就是我目前所拥有的:
<html lang="en">
<head>
<meta charset="utf-8">
<title>topping placement</title>
<style type="text/css">
.ButtonClicked {
background-color:#8C0221;
}
.thumb{
float:left;
width:100px;
height:100px;
cursor:pointer;
}
.crust{
float:right;
padding:100px;
width:220px;
height:160px;
cursor:pointer;
position:absolute;
}
.toppings{
float:right;
padding:100px;
width:220px;
height:160px;
cursor:pointer;
position:absolute;
display: none;
opactiy: 0;
}
.button-whole{
background-image: url(../images/button-whole.png);
background-repeat: no-repeat;
border: none;
width:30px;
height:30px;
cursor:pointer;
}
.button-l{
background-image: url(../images/button-l.png);
background-repeat: no-repeat;
border: none;
width:30px;
height:30px;
cursor:pointer;
}
.button-r{
background-image: url(../images/button-r.png);
background-repeat: no-repeat;
border: none;
width:30px;
height:30px;
cursor:pointer;
}
</style>
<script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
</head>
<body>
<div id="topping-buttons">
<button id="pep-l" class="button-l" type="submit"></button>
<button id="pep-w" class="button-whole" type="submit"></button>
<button id="pep-r" class="button-r" type="submit"></button>
</div>
<img class="crust" src="../images/crust/thinNcrispy.png" alt="" />
<pepperoni>
<img class="toppings" src="../images/toppings/pepperoni.png" alt="" />
</pepperoni>
<olives_black>
<img class="toppings" src="../images/toppings/olives_black.png" alt="" />
</olives_black>
<script>
$("#topping-buttons button").click(function() {
var newval = $("#topping-buttons button").val();
if (newval == "#pep-l"){
$( "#pep-l" ).toggleClass('ButtonClicked');
$( "pepperoni img" ).fadeToggle( "fast", "linear" );
} else if (newval == "#pep-w"){
$( "#pep-w" ).toggleClass('ButtonClicked');
$( "pepperoni img" ).fadeToggle( "fast", "linear" );
} else if (newval == "#pep-r"){
$( "#pep-r" ).toggleClass('ButtonClicked');
$( "pepperoni img" ).fadeToggle( "fast", "linear" );
}
});
</script>
</body>
</html>
【问题讨论】:
-
请详细说明卡住是什么意思?到目前为止你得到了什么?
-
我已经设法完成了 ajax 部分,但无法让 jquery 部分工作。我让这个 jquery 可以使用 2 个按钮(带切换),但我不知道如何使用 3 个按钮。
标签: jquery switch-statement toggle