我到處找關於如何阻止事件冒泡出現一個代碼,我發現一個從怪異模式的網站,這是這樣的:如何使用事件冒泡取消
function doSomething(e){
if(!e) var e = window.event;
e.cancelBubble = true;
if(e.stopPropagation) e.stopPropagation();
}
但我不知道如何以及在哪裏使用它。 什麼是'e'參數用作(或者應該作爲'e'傳遞什麼)? 是否在事件處理程序代碼中調用此函數? ...等等?
我需要一些幫助,請有人給我一些提示?
基本上,我有4個元素有一個名爲 'updateAvailableAttributes()' 的 '平變化' 的處理程序,就像這樣:
<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)'和'updateAvailableAttributes()'合併到'onchange'事件處理函數中?
預先感謝您。
@Vinay B R:謝謝你的迴應。我編輯了我的問題,使其更清晰。 – Shaoz 2010-09-08 14:12:06
我還是新來的JavaScript,所以事件冒泡問題仍然有點令我困惑。我只想將doSomthing()與我已經在'onchange'處理函數中的函數合併。但我該怎麼做? – Shaoz 2010-09-08 14:22:28
如果您可以將您現有的腳本粘貼到此處,我可以爲您編輯 – 2010-09-08 15:07:33