[英]Changing a label to a link in jquery library
我有一个asp.net mvc4应用程序,我想在其中添加一个treeview。 所以我用了这个Jquery库: graphdracula
<html>
<head>
<!-- jQuery -->
<script type="text/javascript" src="~/Content/Scripts/jquery-1.4.2.min.js"></script>
<!-- The Raphael JavaScript library for vector graphics display -->
<script type="text/javascript" src="~/Content/Scripts/raphael-min.js"></script>
<!-- Dracula -->
<!-- An extension of Raphael for connecting shapes -->
<script type="text/javascript" src="~/Content/Scripts/dracula_graffle.js"></script>
<!-- Graphs -->
<script type="text/javascript" src="~/Content/Scripts/dracula_graph.js"></script>
<script type="text/javascript" src="~/Content/Scripts/dracula_algorithms.js"></script>
<script type="text/javascript">
//Show UCLA CS class dependencies (not complete)
$(document).ready(function () {
var width = $(document).width() -500;
var height = $(document).height();
var g = new Graph();
g.edgeFactory.template.style.directed = true;
g.addEdge("Projet", "Fonction1");
g.addEdge("Fonction1", "Sous Fonction 1.1");
g.addEdge("Fonction1", "Sous Fonction 1.2");
g.addEdge("Projet", "Fonction2");
g.addEdge("Fonction2", "Sous Fonction 2.1");
g.addEdge("Fonction2", "Sous Fonction 2.2");
g.addEdge("Fonction2", "Sous Fonction 2.3");
g.addEdge("Fonction2", "Sous Fonction 2.4");
var layouter = new Graph.Layout.Ordered(g, topological_sort(g));
var renderer = new Graph.Renderer.Raphael('canvas', g, width, height);
});
</script>
</head>
<body>
<div id="canvas"></div>
</body>
</html>
结果是这样的视图:
很好,但是我需要将每个标题更改为这样的链接: @Html.ActionLink("Projet", "Modify_Project")
如何修改代码段以执行此任务?
如果您使用的是jQuery。
// on page load
$(function(){
// You need to identify a selector that selects all the titles you want to change..
// Likely they all have a certain class
$('.titleSelector').changeElementType("a");
// Now you probably want to add an href
$('a.titleSelector').attr('href','http://youlinkhere');
});
这是插件。在加载jquery之后且脚本运行https://stackoverflow.com/a/8584217/602379之前包含此插件。
(function($) {
$.fn.changeElementType = function(newType) {
var attrs = {};
$.each(this[0].attributes, function(idx, attr) {
attrs[attr.nodeName] = attr.nodeValue;
});
this.replaceWith(function() {
return $("<" + newType + "/>", attrs).append($(this).contents());
});
};
})(jQuery);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.