简体   繁体   English

访问ajax.actionlink“要显示的文本”

[英]accessing ajax.actionlink “text to display”

if I have an ajax.actionlink 如果我有一个ajax.actionlink

@Ajax.ActionLink("Add Last Name", // <-- Text to display
     "AddTimeSeriesData", // <-- Action Method Name
      etc....
      @id = "link")

how can I access the "text to display" (the link text) in javascript? 如何在javascript中访问“要显示的文本”(链接文本)?

I tried 我试过了

$('#link').innerHTML 

but that didn't work and doesn't seem right... I just tried 但这没用,看起来也不对。。。我只是试过

console.log($('#link'));

and under innerHTML and innerText I got the same value I'm looking for (the link text) but when I try to do 在innerHTML和innerText下,我得到的值是我正在寻找的值(链接文本),但是当我尝试做时

console.log($('#link').innerHTML); //or innerText

I get "undefined" 我得到“未定义”

Check that you are actually adding the id attribute (you haven't shown the full code so hard to tell if its correct). 检查您是否确实在添加id属性(您没有显示完整的代码,因此很难分辨其是否正确)。 Should be something like 应该是这样的

@Ajax.ActionLink("Add Last Name", "AddTimeSeriesData", null, new AjaxOptions { }, new { ID = "link" })

Then you can access the text with 然后,您可以使用

var displayText = $('#link').text();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM