私は異なるIDを持つ5つのコンテナを持っています。 各コンテナには、現在のコンテナと接続されているコンテナを選択するためのボタンがあります。jQuery動的に変更されたonclickクラスを持つ要素の選択と解除
これまでのところ、コンテナの選択は期待通りに機能します。 しかし、コンテナの選択を解除したいときは、istは機能しません。
スクリプトの計算部分は無視してください。
<script type="text/javascript">
$(document).ready(function(){
var pricepermod = '';
var priceperemp = '';
var priceperloc = '';
var priceperusr = '';
var priceperpor = '';
var price = '';
$("#price-calculator input").change(function(){
$(this).pricecalc();
});
$.fn.pricecalc = function(){
var pricepermod = 10;
var priceperemp = 1;
var priceperloc = 10;
var priceperusr = 10;
var priceperpor = 1;
// alert("funktion aufgerufen");
var priceemp = $("#numemp").val() * priceperemp;
var priceloc = $("#numloc").val() * priceperloc;
var priceusr = $("#hruser").val() * priceperusr;
var pricepor = $("#empport").val() * priceperpor;
var pricemod = $("#nummod").val() * pricepermod;
price = pricemod + priceemp + priceloc + priceusr + pricepor;
$("#moncost").val(price);
}
$("#dpa.pricebox a.pricebutton").click(function() {
alert("DPA");
pricepermod = 1;
$("#nummod").val(pricepermod);
$("#dpa").removeClass("pricebox").addClass("pricebox-selected");
$("#dms").removeClass("pricebox-selected").addClass("pricebox");
$("#mms").removeClass("pricebox-selected").addClass("pricebox");
$("#tms").removeClass("pricebox-selected").addClass("pricebox");
$("#bms").removeClass("pricebox-selected").addClass("pricebox");
$("#mms a.pricebutton").html("deselect");
$("#dms a.pricebutton").html("select");
$("#dpa a.pricebutton").html("select");
$("#tms a.pricebutton").html("select");
$("#bms a.pricebutton").html("select");
$(this).pricecalc();
event.preventDefault();
});
$("#dpa.pricebox-selected > a.pricebutton").click(function() {
alert("DPA selected");
pricepermod = 0;
$("#nummod").val(pricepermod);
$("#dpa").removeClass("pricebox-selected").addClass("pricebox");
$("#dms").removeClass("pricebox-selected").addClass("pricebox");
$("#mms").removeClass("pricebox-selected").addClass("pricebox");
$("#tms").removeClass("pricebox-selected").addClass("pricebox");
$("#bms").removeClass("pricebox-selected").addClass("pricebox");
$("#mms a.pricebutton").html("select");
$("#dms a.pricebutton").html("select");
$("#dpa a.pricebutton").html("select");
$("#tms a.pricebutton").html("select");
$("#bms a.pricebutton").html("select");
$(this).pricecalc();
event.preventDefault();
});
$("#dms.pricebox a.pricebutton").click(function() {
alert("DMS");
pricepermod = 2;
$("#nummod").val(pricepermod);
$("#dpa").removeClass("pricebox").addClass("pricebox-selected");
$("#dms").removeClass("pricebox").addClass("pricebox-selected");
$("#mms").removeClass("pricebox-selected").addClass("pricebox");
$("#tms").removeClass("pricebox-selected").addClass("pricebox");
$("#bms").removeClass("pricebox-selected").addClass("pricebox");
$("#dpa a.pricebutton").html("deselect");
$("#dms a.pricebutton").html("deselect");
$("#mms a.pricebutton").html("select");
$("#tms a.pricebutton").html("select");
$("#bms a.pricebutton").html("select");
$(this).pricecalc();
event.preventDefault();
});
$("#dms.pricebox-selected a.pricebutton").click(function() {
alert("DMS selected");
pricepermod = 1;
$("#nummod").val(pricepermod);
$("#dpa").removeClass("pricebox").addClass("pricebox-selected");
$("#dms").removeClass("pricebox-selected").addClass("pricebox");
$("#mms").removeClass("pricebox-selected").addClass("pricebox");
$("#tms").removeClass("pricebox-selected").addClass("pricebox");
$("#bms").removeClass("pricebox-selected").addClass("pricebox");
$("#mms a.pricebutton").html("deselect");
$("#dms a.pricebutton").html("select");
$("#dpa a.pricebutton").html("select");
$("#tms a.pricebutton").html("select");
$("#bms a.pricebutton").html("select");
$(this).pricecalc();
event.preventDefault();
});
$("#mms.pricebox a.pricebutton").click(function() {
alert("MMS");
pricepermod = 3;
$("#nummod").val(pricepermod);
$("#dpa").removeClass("pricebox").addClass("pricebox-selected");
$("#dms").removeClass("pricebox").addClass("pricebox-selected");
$("#mms").removeClass("pricebox").addClass("pricebox-selected");
$("#tms").removeClass("pricebox-selected").addClass("pricebox");
$("#bms").removeClass("pricebox-selected").addClass("pricebox");
$("#dms a.pricebutton").html("deselect");
$("#dpa a.pricebutton").html("deselect");
$("#mms a.pricebutton").html("deselect");
$("#tms a.pricebutton").html("select");
$("#bms a.pricebutton").html("select");
$(this).pricecalc();
event.preventDefault();
});
$("#mms.pricebox-selected a.pricebutton").click(function() {
alert("MMS selected");
pricepermod = 2;
$("#nummod").val(pricepermod);
$("#dpa").removeClass("pricebox").addClass("pricebox-selected");
$("#dms").removeClass("pricebox").addClass("pricebox-selected");
$("#mms").removeClass("pricebox-selected").addClass("pricebox");
$("#tms").removeClass("pricebox-selected").addClass("pricebox");
$("#bms").removeClass("pricebox-selected").addClass("pricebox");
$("#mms a.pricebutton").html("deselect");
$("#dms a.pricebutton").html("deselect");
$("#dpa a.pricebutton").html("select");
$("#tms a.pricebutton").html("select");
$("#bms a.pricebutton").html("select");
$(this).pricecalc();
event.preventDefault();
});
$("#tms.pricebox a.pricebutton").click(function() {
alert("TMS");
pricepermod = 4;
$("#nummod").val(pricepermod);
$("#dpa").removeClass("pricebox").addClass("pricebox-selected");
$("#dms").removeClass("pricebox").addClass("pricebox-selected");
$("#mms").removeClass("pricebox").addClass("pricebox-selected");
$("#tms").removeClass("pricebox").addClass("pricebox-selected");
$("#bms").removeClass("pricebox-selected").addClass("pricebox");
$("#dms a.pricebutton").html("deselect");
$("#dpa a.pricebutton").html("deselect");
$("#mms a.pricebutton").html("deselect");
$("#tms a.pricebutton").html("deselect");
$("#bms a.pricebutton").html("select");
$(this).pricecalc();
event.preventDefault();
});
$("#tms.pricebox-selected a.pricebutton").click(function() {
alert("TMS selected");
pricepermod = 3;
$("#nummod").val(pricepermod);
$("#dpa").removeClass("pricebox").addClass("pricebox-selected");
$("#dms").removeClass("pricebox").addClass("pricebox-selected");
$("#mms").removeClass("pricebox").addClass("pricebox-selected");
$("#tms").removeClass("pricebox-selected").addClass("pricebox");
$("#bms").removeClass("pricebox-selected").addClass("pricebox");
$("#mms a.pricebutton").html("deselect");
$("#dms a.pricebutton").html("deselect");
$("#dpa a.pricebutton").html("deselect");
$("#tms a.pricebutton").html("select");
$("#bms a.pricebutton").html("select");
$(this).pricecalc();
event.preventDefault();
});
$("#bms.pricebox a.pricebutton").click(function() {
alert("BMS");
pricepermod = 5;
$("#nummod").val(pricepermod);
$("#dpa").removeClass("pricebox").addClass("pricebox-selected");
$("#dms").removeClass("pricebox").addClass("pricebox-selected");
$("#mms").removeClass("pricebox").addClass("pricebox-selected");
$("#tms").removeClass("pricebox").addClass("pricebox-selected");
$("#bms").removeClass("pricebox").addClass("pricebox-selected");
$("#dms a.pricebutton").html("deselect");
$("#dpa a.pricebutton").html("deselect");
$("#mms a.pricebutton").html("deselect");
$("#tms a.pricebutton").html("deselect");
$("#bms a.pricebutton").html("deselect");
$(this).pricecalc();
event.preventDefault();
});
$("#bms.pricebox-selected a.pricebutton").click(function() {
alert("BMS selected");
pricepermod = 4;
$("#nummod").val(pricepermod);
$("#dpa").removeClass("pricebox").addClass("pricebox-selected");
$("#dms").removeClass("pricebox").addClass("pricebox-selected");
$("#mms").removeClass("pricebox").addClass("pricebox-selected");
$("#tms").removeClass("pricebox").addClass("pricebox-selected");
$("#bms").removeClass("pricebox-selected").addClass("pricebox");
$("#mms a.pricebutton").html("deselect");
$("#dms a.pricebutton").html("deselect");
$("#dpa a.pricebutton").html("deselect");
$("#tms a.pricebutton").html("deselect");
$("#bms a.pricebutton").html("select");
$(this).pricecalc();
event.preventDefault();
});
});
<body>
<div id="dpa" class="pricebox">
<h2>DPA</h2>
<a href="#" class="pricebutton">auswählen</a>
</div>
<div id="dms" class="pricebox">
<h2>DMS</h2>
<a href="#" class="pricebutton">auswählen</a>
</div>
<div id="mms" class="pricebox">
<h2>MMS</h2>
<a href="#" class="pricebutton">auswählen</a>
</div>
<div id="tms" class="pricebox">
<h2>TMS</h2>
<a href="#" class="pricebutton">auswählen</a>
</div>
<div id="bms" class="pricebox">
<h2>BMS</h2>
<a href="#" class="pricebutton">auswählen</a>
</div>
<form id="price-calculator">
<p>Anzahl Mitarbeiter <input type="text" name="numemp" id="numemp" class="form-control" value="0"></p>
<hr />
<p>Anzahl Standorte <input type="text" name="numloc" id="numloc" class="form-control" value="0"></p>
<p>Anzahl HR-Anwender <input type="text" name="hruser" id="hruser" class="form-control" value="0"></p>
<p>Anzahl Mitarbeiterportale <input type="text" name="empport" id="empport" class="form-control" value="0"></p>
<hr />
<p>gewählte Module <input type="text" name="nummod" id="nummod" class="form-control" value="0" /></p>
<p>Monatliches Nutzungsentgeld <input type="text" name="moncost" id="moncost" class="form-control" value="0" /> (€/mtl.)</p>
</form>
</body>
誰かがここに私を助けてくださいことはできますか? は、私はすでに私はhereを見つけたさまざまなソリューションをしようとしていますが、何も:(
PSを動いていないようにみえ:。申し訳ありません悪いコードのために私はjQueryの専門家ではないです
あなたのフィドルページのリンクを更新します。それは動作していません – want2learn