jQuery菜单href替换 [英] jQuery menu href replacement
问题描述
我有一个具有水平布局的控件,并且由基于用户的XML文件提供数据。当我在开发中运行页面时,HOME节点上的鼠标悬停将被jQuery脚本替换。当我点击菜单的另一部分时,Home节点不会被替换。
Menu控件的来源如下所示:
< pre lang =xml>< ul class =level1>
< li>
< a class =level1href =#onclick =__ doPostBack(&#39; ctl00 $ Menu1&#39;,&#39; Home&#39;)> Home< ; / A>< /锂>
< li>< a class =level2href =default.aspx>销售< / a>< ul class =level3>
我的ASPX页面中有以下脚本:
< script 类型 = text / javascript >
window.onload = function(){
alert(welcome);
$('。level1')。attr('href','http://www.google.com');
}
< / script >
当我启动页面时,主页节点将重定向到google.com。当我单击菜单上的第二个节点时,页面呈现,但目标URL不再被替换。
源代码如下:
< li > < span class =code-keyword>< a class = level1 href = # önclick = __ doPostBack('ctl00 $ Menu1','Home') > 主页< / a > < / li >
如何在每次点击菜单时启动脚本?当我在调试中启动站点时,菜单会替换链接。但是,如果我点击菜单中的其他项目,则更换无法完成。
**我明白这可能是一个hacky解决方案。站点地图文件不适合我的目的,所以我试图解决无法在菜单顶部节点上设置URL的限制
< blockquote> Menu1&#39;,&#39; Home&#39;)> Home< / a>< / li>
< li>< a class =level2href = default.aspx>销售< / a>< ul class =level3>
我有以下脚本在我的ASPX页面中:
< script type = text / javascript >
window.onload = function() {
alert(welcome);
('。level1')。attr('href','http://www.google.com');
}
< / script >
当我启动页面时,主页节点将重定向到google.com。当我单击菜单上的第二个节点时,页面呈现,但目标URL不再被替换。
源代码如下:
< li > < span class =code-keyword>< a class = level1 href = # önclick = __ doPostBack('ctl00
Menu1','Home')
> 主页< / a > < / li >
如何在每次点击菜单时启动脚本?当我在调试中启动站点时,菜单会替换链接。但是,如果我点击菜单中的其他项目,则更换无法完成。
**我明白这可能是一个hacky解决方案。站点地图文件不适合我的目的,所以我试图解决无法在菜单的顶部节点上设置URL的限制
I have an control that has a horizontal layout, and is supplied data by an XML file based on the user. When I run the page in development, the mouseover on the HOME node gets replaced by the jQuery script. When I click on another part of the menu, the Home node does not get replaced.
The source of the Menu control renders like this:
<pre lang="xml"><ul class="level1"> <li> <a class="level1" href="#" onclick="__doPostBack('ctl00$Menu1','Home')">Home</a></li> <li><a class="level2" href="default.aspx">Sales</a><ul class="level3">
I have the following script in my ASPX page:
<script type="text/javascript">
window.onload = function () {
alert("welcome");
$('.level1').attr('href', 'http://www.google.com');
}
</script>
When I launch the page, the Home node will redirect to google.com. When I click a second node on the menu, the page renders, but the target URL no longer gets replaced.
The source looks like:
<li><a class="level1" href="#" önclick="__doPostBack('ctl00$Menu1','Home')">Home</a></li>
How to I get the script to fire off on each click of the menu? When I launch the site in debug, the menu does replace the link. But if I click on another item in the menu, the replacement does not get done.
** I understand this might be a hacky solution. A sitemap file doesn't suit my purpose, so I'm trying to get around the limitation of not being able to set the URL on the top node of the menu
Menu1','Home')">Home</a></li> <li><a class="level2" href="default.aspx">Sales</a><ul class="level3">
I have the following script in my ASPX page:
<script type="text/javascript"> window.onload = function () { alert("welcome");
('.level1').attr('href', 'http://www.google.com'); } </script>
When I launch the page, the Home node will redirect to google.com. When I click a second node on the menu, the page renders, but the target URL no longer gets replaced.
The source looks like:
<li><a class="level1" href="#" önclick="__doPostBack('ctl00
Menu1','Home')">Home</a></li>
How to I get the script to fire off on each click of the menu? When I launch the site in debug, the menu does replace the link. But if I click on another item in the menu, the replacement does not get done.
** I understand this might be a hacky solution. A sitemap file doesn't suit my purpose, so I'm trying to get around the limitation of not being able to set the URL on the top node of the menu
这篇关于jQuery菜单href替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!