我有一个 jQuery 通知。当我点击通知时,它应该进入预期的页面。
在 PHP 中,我们可以通过执行以下操作来实现这一点。
$link = 22;
echo "<a href=\"page2.php?id=link\">Click to read more</a>";
如何在 JQuery 中实现这样的功能?我已弹出通知并准备好链接变量。
var link = "home.php?destination=22";
最佳答案
您可以使用 jQuery 创建 HTML 元素
var link = "home.php?destination=22";
//Create anchor element
var anchor = $('<a />', {
"href": link,
"text": "Click to read more"
})
//Append the element
$('#dialog').append(anchor).dialog();
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<div id="dialog" title="Basic dialog">
</div>
关于php - 如何在 jQuery 中创建链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38995163/