<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标签的对象