zoukankan      html  css  js  c++  java
  • <a href="onclick="javascript:goSearch(this)" class="click" name="Java">Java</a>为什么a标签的父节点获取不到

    <script>

    function goSearch(event) {
    //var select = $('#keyInput').val($(event).attr("name"));
    var hotkey = $(event).attr("name");
    var inputkey=$('#keyInput').val();
    var searchUrl = "http://localhost:8959/CampusPostSearch.aspx?t=";
    searchUrl = searchUrl + "&zw=";
    searchUrl = searchUrl + "&cs=";
    searchUrl = searchUrl + "&we=1001"; //bys站点只搜索工作经验为'应届生'的职位(1001)
    if (hotkey == undefined) var searchKey = inputkey;
    else var searchKey = hotkey;
    //if (searchKey == "请输入职位或公司关键字") searchKey = "";
    searchUrl = searchUrl + "&qt=" + encodeURI(searchKey);
    window.location.href = searchUrl;
    //window.open(searchUrl);
    }

      }

    </script>
    <div name="d1"><a id="a1" href="javascript:goSearch(this)"> 点 DIV 1 出错</a></div>
    <div name="d2"><a id="a2" href="#" onclick="javascript:goSearch(this)">点 DIV 2 正常</a></div>
    <div name="d3"><a id="a3" href="javascript:goSearch(document.getElementById('a3'))">点 DIV 3 正常</a></div>

    感觉主要的问题不在于标签,而在于调用函数时传入的 this。
    1. this用于href中不正常
    2. this用于事件中如onclick中正常。
    3. href中如果不用this,用document.getElementById("a3")传入一个确定对象,正常。

    原因粗解,第一个取到的window对象,第二三取到的才是a标签的对象
  • 相关阅读:
    office 2007
    关于网站爬虫的爬取
    华为交换机默认密码大合集
    一些不错的网站工具箱
    HDU 2023 求平均成绩
    HDU 2056 Rectangles
    HDU 2022 海选女主角
    HDU 2045 不容易系列之(3)—— LELE的RPG难题
    HDU 2042 不容易系列之二
    HDU 2044 一只小蜜蜂...
  • 原文地址:https://www.cnblogs.com/zhanghongqiang/p/3977050.html
Copyright © 2011-2022 走看看