【发布时间】:2010-09-08 13:44:29
【问题描述】:
我到处寻找有关如何阻止事件冒泡发生的代码,我在 Quirksmode 网站上找到了一个,它是这样的:
function doSomething(e){
if(!e) var e = window.event;
e.cancelBubble = true;
if(e.stopPropagation) e.stopPropagation();
}
但我不知道如何以及在哪里使用它。 'e' 参数用作什么(或者应该作为 'e' 传递什么)? 是否要在事件处理程序代码中调用此函数? ...等等?
我需要一些帮助,请有人给我一些提示吗?
基本上,我有 4 个元素有一个名为“updateAvailableAttributes()”的“onchange”处理程序,如下所示:
<select id="deliveryMethod" name="deliveryMethod" onchange="updateAvailableAttributes();"></select>
<select id="formatMethod" name="formatMethod" onchange="updateAvailableAttributes();"></select>
<select id="yearsMethod" name="yearsMethod" onchange="updateAvailableAttributes();"></select>
<select id="updateMethod" name="updateMethod" onchange="updateAvailableAttributes();"></select>
这里是 updateAvailableAttributes() 脚本:
function updateAvailableAttributes() {
var form = document.forms["orderDefinition"];
form.elements["formChangeRequest"].value = "true";
$.ajax({
type: "POST",
url: "ajax/possibleValues.html",
data: $("form#orderDefinition").serialize(),
success: function(response){
$('#usercontent .sleeve .toprow').html(response);
applyValidation();
radioButtonHighlightSelection();
},
error: function(response, ioArgs) {
if (response.status == 601) {
sessionTimedOut();
}
}
});
// Display a "please wait" message
$("#waitingMsgOverlay, #waitingMsgBox, #waitingMsg, #waitingMsgParag").ajaxStart(function(){
var map = document.getElementById("OrderMap");
map.disableApplication();
$(this).show();
radioButtonHighlightSelection();
}).ajaxStop(function(){
var map = document.getElementById("OrderMap");
map.enableApplication();
$(this).hide();
$("#toolpanel").height($("#orderMap").height());
radioButtonHighlightSelection();
});}
我的问题是,如何将“doSomething(e)”与“onchange”事件处理程序中已有的“updateAvailableAttributes()”结合起来?
提前谢谢你。
【问题讨论】:
标签: javascript events event-bubbling