即时通讯尝试绑定五个不同的元素与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