JQUERY href 禁用问题
我目前正在开发一个自制的完整前台 100% javascript CMS,但我遇到了很大的问题。 用户可以编辑的一些可编辑区域包含在 href 链接中。这些 href 是不可编辑的,但是,当用户单击这些区域(在编辑模式下)时,浏览器会跟踪这些链接。
首先,这是 CMS 生成的 html 示例:
<span id ="8a8b8d2e262bde2d01262c08317c000c" class="document">
<a href="/actions/ecommerce/viderSelectionPalierEtVitrine">
<img src="/images/logo.gif" id="8a8b8d2e262bde2d01262c08bf83000d" title="" alt="" class="image logo" />
</a>
</span>
例如,用户只能更改 ; 所以我尝试以这种方式管理周围的href:
var referenceZone = $(this).attr("id");
$("#"+documentId+" a").each(function() {
$(this).click(function() {
return false;
});
});
其中referenceZone是我周围的
这在我看来是那么棘手吗?
<**** 编辑 ****> 此处添加了用于测试目的的沙箱:http://jsbin.com/aboke/2 <
* *** 编辑 2 ****> 我不明白的是,alert(event.type) 甚至没有启动!
//click event disabling on any href of curently edited ${"span.document"}
$("span#" + documentId + " a").click(function(event) {
alert(event.type);
event.preventDefault();
suppressionZoneModifiable(documentId);
recupererTexte(referenceZone, documentId);
});
I'm currently working on a home-made full front-office 100% javascript CMS of ours, and I'm having quite a problem.
Some of the editable areas the user can edit are contained in href link. These href's are NOT editable, yet, when the user clicks on these zones (while in edition mode) browser follows these links.
First, heres an example of html generated by the CMS :
<span id ="8a8b8d2e262bde2d01262c08317c000c" class="document">
<a href="/actions/ecommerce/viderSelectionPalierEtVitrine">
<img src="/images/logo.gif" id="8a8b8d2e262bde2d01262c08bf83000d" title="" alt="" class="image logo" />
</a>
</span>
Here, for example, the user can only change the ;
So I tried to manage the surrounding href that way :
var referenceZone = $(this).attr("id");
$("#"+documentId+" a").each(function() {
$(this).click(function() {
return false;
});
});
Where referenceZone is my surrounding <span id ="8a8b8d2e262bde2d01262c08317c000c" class="document">
Is this as tricky as it seems to me ?
<**** EDIT ****>
Added a sandbox for testing purposes here : http://jsbin.com/aboke/2
<**** EDIT 2 ****>
What I don't understand is that alert(event.type) doesn't even fire up !!
//click event disabling on any href of curently edited ${"span.document"}
$("span#" + documentId + " a").click(function(event) {
alert(event.type);
event.preventDefault();
suppressionZoneModifiable(documentId);
recupererTexte(referenceZone, documentId);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,这是可能的,但不能通过 return 语句。使用preventDefault();
另外,除非您对链接执行任何其他操作,否则无需执行 .each() 。但使用 event.preventDefault()。
请参阅文档的其余部分。
Yes, it is possible, but not via return statement. Use preventDefault();
Also, there's no need to do a .each() unless you're doing anything else with the links. But use event.preventDefault().
See rest of the documentation.
您位于 http://jsbin.com/aboke/2 的沙箱代码有许多错误。以下是一些:
1。函数参数是一个字符串,但作为数字传递
您应该在此处的参数两边加上引号:
2.参数与范围 ID 不匹配
8a8b8d2e262bde2d01262c08317c000c
与8a8b8d2e262bde2d01262c08bf83000d
3.您在 jQuery 中使用 onclick 而不是 click
应该是
4。你有一个 js 错误
“参数列表后缺少 )”(第 81 行)
Your sandbox code at http://jsbin.com/aboke/2 has many errors. Here's a few:
1. the function argument is a string, but passed as a number
You should put quotes around the argument here:
2. the argument does not match the span id
8a8b8d2e262bde2d01262c08317c000c
vs.8a8b8d2e262bde2d01262c08bf83000d
3. You are using onclick instead of click in jQuery
should be
4. You have a js error
"missing ) after argument list" (line 81)
^ 不起作用。使用
$(...).click()
将该函数添加到单击时执行的函数列表中。它不会删除跟踪链接的默认行为。您可以通过执行以下操作来覆盖默认链接操作:
^ doesn't work. Using
$(...).click()
adds that function to the list of functions it executes upon clicking. It does not remove the default behavior of following the link.You can override the default link action by doing: