我在更改锚标记中的 href 值时遇到问题。基本上,我想使用一个线索提示,它根据已登录用户的员工 ID 打开一个工具提示页面。
提示代码:
$(document).ready
(
function () {
$('#sticky').cluetip({ sticky: true, closePosition: 'title', arrows: true });
$('a.jt:eq(0)').cluetip({
cluetipClass: 'jtip',
arrows: true,
dropShadow: false,
hoverIntent: false,
sticky: true,
mouseOutClose: true,
closePosition: 'title',
closeText: '<img src="Images/cross.png" alt="close"/>'
});
}
现在,可以看到锚标签:
<a class="jt" style="color: #FFFFFF;" id="Anchor_work" runat="server" href='WorkExp.aspx?Emplid=12345'>Previous Work Experience</a>
我正在尝试使用 jquery 更改 href 链接以指向正确的员工 ID。所以,我想将员工 ID 的值存储在 DIV 中。
<div id="Workexp_div" runat="server"/>
JQuery 使用 DIV 标签更改 href:
$(document).ready
(
function () {
$('#sticky').cluetip({ sticky: true, closePosition: 'title', arrows: true });
$('a.jt:eq(0)').cluetip({
cluetipClass: 'jtip',
arrows: true,
dropShadow: false,
hoverIntent: false,
sticky: true,
mouseOutClose: true,
closePosition: 'title',
closeText: '<img src="Images/cross.png" alt="close"/>'
});
function showDivText() {
//divObj = document.getElementById('Workexp_Div');
divObj = document.getElementById("#<%= Workexp_Div.ClientID %>");
if (divObj) {
if (divObj.textContent) { // FF
alert(divObj.textContent);
} else { // IE
alert(divObj.innerText); //alert ( divObj.innerHTML );
}
}
}
//var new_href = "WorkExp.aspx?Emplid=" + $('#ctl00_ContentPlaceHolder1_Workexp_div').InnerText;
var new_href = "WorkExp.aspx?Emplid=" + showDivText();
$("#Anchor_work").attr("href", new_href);
//= 'WorkExp.aspx?Emplid='+ $('#ctl00_ContentPlaceHolder1_Workexp_div').InnerText;
}
);
上面的代码给了我一个错误,说 WorkExp_div 在当前上下文中不存在。我尝试通过删除客户端 ID 执行 divObj = document.getElementById('Workexp_Div'); 但随后该对象返回为空。
谁能告诉我如何检索 div 标签的值并更改标签中 href 的值?
非常感谢