开发者

Jquery returning Object DomWindow

I am trying to get the value of a link, but instead of the link as my object I am getting [Object DOMWindow] in the alert.

Here is my code:

<script type="text/javascript">
function showToggle(link) {
   var x = this
   alert(x);
}
</script>


<a class=开发者_JS百科"toggleLink" href="#" onclick="showToggle(this);">Sharing</a>

I am adding this code to a page. There is much more code that is not included. I only showed when I added.


The way you're calling it, this is the same as window, hence the result. You want

var x = link;


By link, do you mean the url? Also, you're using this as the variable, not link, which returns the window, not the link.

This will work:

function showToggle(link) {
   var x = link.href;
   alert(x);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜