dsw*_*tik 5 asp.net-mvc jquery
我有以下代码,它执行的功能类似于注释链接在Stackoverflow上的工作方式...单击时触发ActionResult并填充div
$(function() {
$("a[id ^='doneLink-']").live('click', function(event) {
match = this.id.match(/doneLink-(\d+)/);
container = $("div#doneContainer-" + match[1])
container.toggle();
if (container.is(":visible")) {
container.load($(this).attr("href"));
} else {
container.html("Loading...");
}
event.preventDefault();
});
});
Run Code Online (Sandbox Code Playgroud)
我希望能够做一件事情改变他们点击的链接文本,说出类似"隐藏"的内容,并禁用此链接所在的小菜单中的其他链接.
编辑: 使用此功能的源代码如下所示
<div id="dc_lifelistmenu"style="float:left;padding-bottom:5px;font-size:10pt;width:400px;">
<a href="/entries/addentry/86">Add Entry</a> |
<a href="/goals/adddaimoku/86" id="daimokuLink-2">Log Daimoku</a> |
<a href="/goals/done/86" id="doneLink-2">Mark Completed</a> |
<a href="/goals/remove/86">Remove</a>
</div><br />
<div id='daimokuContainer-2' style="display:none;"> Loading...</div>
<div id='doneContainer-2' style="display:none;"> Loading...</div>
Run Code Online (Sandbox Code Playgroud)
小智 9
如果要删除链接而不是禁用它:
jQuery('#path .to .your a').each(function(){
var $t = jQuery(this);
$t.after($t.text());
$t.remove();
});
Run Code Online (Sandbox Code Playgroud)
笔记:
要修改函数内的链接文本,只需使用:
this.text('New Text!');
Run Code Online (Sandbox Code Playgroud)
要禁用其他文本,我们必须查看页面的来源。我不确定你所说的“其他链接”是什么意思......
更新:根据您的编辑,我猜您想要什么:
$(function() {
$("a[id ^='doneLink-']").live('click', function(event) {
match = this.id.match(/doneLink-(\d+)/);
container = $("div#doneContainer-" + match[1])
container.toggle();
if (container.is(":visible")) {
container.load($(this).attr("href"));
} else {
container.html("Loading...");
}
event.preventDefault();
// added
this.text('Hide');
// disable others manually, repeat and adjust for each link
$("#daimokuLink-" + match[1]).toggle();
// or in one shot, all but the one I clicked
$("#dc_lifelistmenu:not(#doneContainer-" + match[1] + ")").toggle();
});
});
Run Code Online (Sandbox Code Playgroud)
更新2:看到你的评论。要禁用链接而不是隐藏它,请onclick通过覆盖它来禁用它,而不是使用toggle().
$("#daimokuLink-" + match[1]).click(function() { return false; });
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30408 次 |
| 最近记录: |