即時通訊嘗試綁定五個不同的元素與click事件具有相同的功能作爲事件處理程序,但具有不同的參數。繼承人是我的代碼:JQuery綁定點擊事件問題
$("#areaascensor").bind("click", setearImagen("ascensor"));
$("#areaflat").bind("click", setearImagen("flat"));
$("#areaduplex").bind("click", setearImagen("duplex"));
$("#areasimple").bind("click", setearImagen("simple"));
$("#areatendales").bind("click", setearImagen("tendales"));
問題是,當我點擊任何元素時,它總是跳轉最後一個事件。在這種情況下setearImagen(「tendales」)。不知道爲什麼:(任何線索?
這裏是使用
<div class="morph-button morph-button-large" id="coordenadas">
<area shape="rect" id="areaflat" coords="129, 50, 381, 152" href="#" style="border: 1px solid;" data-maphilight="{" strokecolor":"000000","strokewidth":1,"fillcolor":"0000ff","fillopacity":0.4}"="">
<area shape="rect" id="areaduplex" coords="129, 154, 383, 283" href="#" style="border: 1px solid;" data-maphilight="{" strokecolor":"000000","strokewidth":1,"fillcolor":"0000ff","fillopacity":0.4}"="">
<area shape="rect" id="areasimple" coords="129, 286, 391, 364" href="#" style="border: 1px solid;" data-maphilight="{" strokecolor":"000000","strokewidth":1,"fillcolor":"0000ff","fillopacity":0.4}"="">
<area shape="rect" id="areatendales" coords="141, 6, 362, 31" href="#" style="border: 1px solid;" data-maphilight="{" strokecolor":"000000","strokewidth":1,"fillcolor":"0000ff","fillopacity":0.4}"="">
<area shape="rect" id="areaascensor" coords="240, 368, 278, 523" href="#" style="border: 1px solid;" data-maphilight="{" strokecolor":"000000","strokewidth":1,"fillcolor":"0000ff","fillopacity":0.4}"="">
股利IM我已經用。對和。點擊,但仍是同樣的問題,試圖
這裏是setearImagen
function setearImagen(tipo){
if(tipo == "flat"){
$("#interiorImg").html('');
$("#interiorImg").append('<img src="https://drive.google.com/uc?export=view&id=0B9LTjyArujnXUVlCM0FIQUZ1UDg" alt="" width="800" height="500" style="padding-right:10px;"/>');
$("#interiorImg").append('<img src="https://drive.google.com/uc?export=view&id=0B9LTjyArujnXRVY3bEpmVThkVk0" alt="" width="400" height="500"/>');
$("#descripcionDepa").text('Apartamento Flat');
}else if(tipo == "duplex"){
$("#interiorImg").html('');
$("#interiorImg").append('<img src="https://drive.google.com/uc?export=view&id=0B9LTjyArujnXM3ZTdU1MTkRCT3c" alt="" width="800" height="500" style="padding-right:10px;"/>');
$("#interiorImg").append('<img src="https://drive.google.com/uc?export=view&id=0B9LTjyArujnXNjc0ajh3bEM2eTg" alt="" width="400" height="500" style="padding-right:10px;"/>');
$("#descripcionDepa").text('Apartamento Duplex');
}else if(tipo == "simple"){
$("#interiorImg").html('');
$("#interiorImg").append('<img src="https://drive.google.com/uc?export=view&id=0B9LTjyArujnXSmFwaTZ2SGVNSE0" alt="" width="800" height="500" style="padding-right:10px;"/>');
$("#interiorImg").append('<img src="https://drive.google.com/uc?export=view&id=0B9LTjyArujnXcThRcXhveTVlams" alt="" width="400" height="500" style="padding-right:10px;"/>');
$("#descripcionDepa").text('Apartamento Simple');
}else if(tipo == "tendales"){
$("#interiorImg").html('');
$("#interiorImg").append('<img src="undefined" alt="" width="800" height="500" style="padding-right:10px;"/>');
$("#interiorImg").append('<img src="undefined" alt="" width="400" height="500" style="padding-right:10px;"/>');
$("#descripcionDepa").text('Tendales');
}else if(tipo == "ascensor"){
$("#interiorImg").html('');
$("#interiorImg").append('<img src="https://drive.google.com/uc?export=view&id=0B9LTjyArujnXMVRuZHlQdVVzSGM" alt="" width="800" height="500" style="padding-right:10px;"/>');
$("#interiorImg").append('<img src="https://drive.google.com/uc?export=view&id=0B9LTjyArujnXNkUyVW1PMjRhSlE" alt="" width="400" height="500" style="padding-right:10px;"/>');
$("#descripcionDepa").text('Ascensor');
}
}
任何的任何其他元素的內部元素?也許你需要告訴我們一些你的HTML – DLeh 2015-01-09 21:17:48
你能發佈一個完整的代碼示例嗎? – j08691 2015-01-09 21:18:59
我沒有看到代碼的猜測是,也許你的事件是冒泡的dom。根據你使用的jQuery版本,你有兩種不同的綁定方法。如果它的jquery 1.7或更低使用綁定,如果它更大,請使用.on – 2015-01-09 21:22:00