我从数据库获取以下文本,其中 href
为 null。
你还需要单击此链接。
当页面加载时,我将此文本分配给标签。
我的需求是,当我单击“链接”时,我需要重定向到某个页面。应该在哪里分配 href
值并如何分配?
我从数据库获取以下文本,其中 href
为 null。
你还需要单击此链接。
当页面加载时,我将此文本分配给标签。
我的需求是,当我单击“链接”时,我需要重定向到某个页面。应该在哪里分配 href
值并如何分配?
<script>
var s = document.getElementByTagName("a");
s.href = ""; // here give the href value
</script>
$("a").attr("href", "http://stackoverflow.com");
<div><%= linkValue %></div>
string linkValue = "You also have to click on is <a href='' target='_blank'> link </a>";
/* Set the page URL where you want to redirect the page. in your case get the value from database. */";
我认为这就是你想要做的事情。从问题中并没有完全清楚。
更新: 如果页面中有多个链接,您需要创建带有标签的链接。 请参考以下代码:
HyperLink link1 = new HyperLink();
link1.Text = "LINK HERE";
link1.NavigateUrl = "http://somedomain.com";
然后像这样添加到容器中
container.Controls.Add(link1);
document.getElementById('myAnchor').href="http://www.google.com";
非常简单 :)
如果您还想更改超链接的URL和文本...
<html>
<head>
<script type="text/javascript">
function myHref(){
document.getElementById('myAnchor').innerHTML="Visit Google"
document.getElementById('myAnchor').href="http://www.google.com"
}
</script>
</head>
<body>
<a id="myAnchor" href="http://www.java2s.com">Visit Java2s</a>
<form>
<input type="button" onclick="myHref()" value="Change URL and text">
</form>
</body>
</html>
来源:java2s