Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQuery-使用Div中的值更改锚标记的href_Jquery_.net_Cluetip - Fatal编程技术网

JQuery-使用Div中的值更改锚标记的href

JQuery-使用Div中的值更改锚标记的href,jquery,.net,cluetip,Jquery,.net,Cluetip,我在更改锚定标记中的href值时遇到问题。基本上,我想使用一个cluetip,它根据登录用户的员工ID打开一个工具提示页面 Cluetip代码: $(document).ready ( function () { $('#sticky').cluetip({ sticky: true, closePosition: 'title', arrows: true }); $('a.jt:eq(0)').cluetip({

我在更改锚定标记中的href值时遇到问题。基本上,我想使用一个cluetip,它根据登录用户的员工ID打开一个工具提示页面

Cluetip代码:

    $(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"/>'
          });
$(文档)。准备好了吗
(
函数(){
$('#sticky').cluetip({sticky:true,closePosition:'title',arrows:true});
$('a.jt:eq(0)').cluetip({
cluetipClass:'jtip',
箭头:是的,
dropShadow:false,
目的:错误,
斯蒂奇:是的,
mouseOutClose:是的,
关闭位置:'标题',
关闭文本:“”
});
}

现在,可以看到锚定标记:

     <a class="jt" style="color: #FFFFFF;" id="Anchor_work"  runat="server" href='WorkExp.aspx?Emplid=12345'>Previous Work Experience</a>

我试图使用jquery将href链接更改为指向正确的员工ID

    <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;           


      }


    );
$(文档)。准备好了吗
(
函数(){
$('#sticky').cluetip({sticky:true,closePosition:'title',arrows:true});
$('a.jt:eq(0)').cluetip({
cluetipClass:'jtip',
箭头:是的,
dropShadow:false,
目的:错误,
斯蒂奇:是的,
mouseOutClose:是的,
关闭位置:'标题',
关闭文本:“”
});
函数showDivText(){
//divObj=document.getElementById('Workexp_Div');
divObj=document.getElementById(“#”);
if(divObj){
if(divObj.textContent){//FF
警报(divObj.textContent);
}否则{//IE
alert(divObj.innerText);//alert(divObj.innerHTML);
}
}
}
//var new_href=“WorkExp.aspx?Emplid=“+$('#ctl00_contentplaceholder 1_WorkExp_div')。InnerText;
var new_href=“WorkExp.aspx?Emplid=“+showDivText();
$(“#锚定工作”).attr(“href”,new#href);
//='WorkExp.aspx?Emplid='+$('#ctl00_contentplaceholder 1_WorkExp_div')。InnerText;
}
);
上面的代码告诉我一个错误,说明当前上下文中不存在WorkExp_div。我尝试通过执行divObj=document.getElementById('WorkExp_div')来删除客户端ID,但随后该对象返回为null

有人能告诉我如何检索div标签的值并更改标签中href的值吗

如果您更换了以下部件,非常感谢

      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 );
              }
          }
      }
函数showDivText(){
//divObj=document.getElementById('Workexp_Div');
divObj=document.getElementById(“#”);
if(divObj){
if(divObj.textContent){//FF
警报(divObj.textContent);
}否则{//IE
alert(divObj.innerText);//alert(divObj.innerHTML);
}
}
}
与:

函数showDivText(){
var divObj=$(“#”);
警报(divObj.text());
返回divObj.text();
}
是否会发出警报并返回正确的值

如果是这样,则可以删除该选项并执行以下操作:

var new_href = "WorkExp.aspx?Emplid=" +  $("#<%= Workexp_Div.ClientID %>").text();
var new_href=“WorkExp.aspx?Emplid=“+$(“#”)text();

谢谢。我尝试了这个。但是,它向我抛出了一个错误,即Workexp_Div在当前上下文中不存在,即使它存在。我用jquery语法出错。我改为这样做,它给了我值。函数showDivText(){var divObj=$(“#ctl00_contentplaceholder 1_Workexp_Div”);警报(divObj.text());return divObj.text();}但是,现在我无法通过使用$(“#ctl00_contentplaceholder 1_Anchor_work”).attr(“href”,new_href”);来更改href值,因此,
可能不会返回客户端id?-关于
警报($(“#”)attr('id')
-请注意,要获取替换服务器端,需要在页面代码而不是外部文件中存在。再次感谢。它仍然不起作用。现在,我可以使用$(“#ctl00_contentplaceholder 1_Workexp_div”)引用。现在href也在更改。但是,cluetip不起作用。也就是说,当我将鼠标悬停在它上面时,该值不会显示:(:(我对cluetip一无所知-但这似乎是另一个问题。
var new_href = "WorkExp.aspx?Emplid=" +  $("#<%= Workexp_Div.ClientID %>").text();