2

我正在尝试使用来自http://www.asual.com/jquery/address/的地址插件,我确实需要能够访问触发 $.address.change 函数的被点击的链接或对象。

所以基本上,我有一个看起来像这样的链接:

<a href="#" class="active" rel="address:/show-my-activity">Activity</a>

然后我有如下所示的 $.address.change 函数:

<script language="javascript">
    $.address.internalChange(function (e) {
         // this is where I need to get the obj of what was clicked to trigger it
         // find out what the e.value is, and do the ajax needed
    });
</script>

我已经遍历了“e”的所有属性,但找不到任何将我引用回被单击对象的内容。这是从“e”变量返回的内容......

undefinedtype value :change
timeStamp value :1317227369056
jQuery1317227368799 value :true
value value :/show-my-activity
path value :/show-my-activity
pathNames value :show-my-activity
parameterNames value :
parameters value :[object Object]
queryString value :
result value :undefined
target value :[object Object]
currentTarget value :[object Object]
handler value :function (e) {
    var str;
    var obj = e;
    for (prop in obj) {
        str += prop + " value :" + obj[prop] + "\n";
    }
    alert(str);
    if (e.value === "/showMyActivity") {
    }
}
data value :undefined
handleObj value :[object Object]
preventDefault value :function () {
    this.isDefaultPrevented = Z;
    var a = this.originalEvent;
    if (a) {
        a.preventDefault && a.preventDefault();
        a.returnValue = false;
    }
}
stopPropagation value :function () {
    this.isPropagationStopped = Z;
    var a = this.originalEvent;
    if (a) {
        a.stopPropagation && a.stopPropagation();
        a.cancelBubble = true;
    }
}
stopImmediatePropagation value :function () {
    this.isImmediatePropagationStopped = Z;
    this.stopPropagation();
}
isDefaultPrevented value :function Y() {
    return false;
}
isPropagationStopped value :function Y() {
    return false;
}
isImmediatePropagationStopped value :function Y() {
    return false;
}

任何帮助将不胜感激。

4

1 回答 1

5

查看此处的文档http://www.asual.com/jquery/address/docs/

您可以在链接的点击事件中执行此操作。

$('a').click(function() {  
    $.address.value($(this).attr('href'));  
});  

然后用event.value.

编辑:我用我认为可能有用的方法更新了上述解决方案。或者,您可以有一个全局变量,将您的对象分配给它的点击事件。然后您可以在其他函数中使用该变量。

于 2011-09-28T16:39:20.000 回答