当前位置: 动力学知识库 > 问答 > 编程问答 >

css - How do I get the text "Job id" from this:

问题描述:

<a name="HRS_AGNT_RSLT_I$srt7$0"

id="HRS_AGNT_RSLT_I$srt7$0"

tabindex="109"

class="PSLEVEL1GRIDCOLUMNHDR" href="javascript:submitAction_win0(document.win0,'HRS_AGNT_RSLT_I$srt7$0');" title="Click column heading to sort descending">Job ID</a>.`

I want to get the "job id" text from the above code.

I've tried everything I could, but still not able to find a way out.

This has really got me stuck on this project for some time now.

I need someone to help me.

网友答案:

Simply use : document.getElementById("myAnchor").text

for example,copy and paste this and tell me if it helped:

<!DOCTYPE html>
<html>
<body>

<p><a id="myAnchor" href="http://www.example.com/test.htm#part2">Example link</a></p>

<p>Click the button to display the text content of the link above.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myAnchor").text;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>
网友答案:

Try using regular expressions.

s = "<a name=\"HRS_AGNT_RSLT_I$srt7$0\" id=\"HRS_AGNT_RSLT_I$srt7$0\" tabindex=\"109\" class=\"PSLEVEL1GRIDCOLUMNHDR\" href=\"javascript:submitAction_win0(document.win0,'HRS_AGNT_RSLT_I$srt7$0');\" title=\"Click column heading to sort descending\">Job ID</a>."
reg = /<a.+>(.+)<\/a>/
s[reg, 1]
# => "Job ID"
分享给朋友:
您可能感兴趣的文章:
随机阅读: