【发布时间】:2011-09-16 12:34:24
【问题描述】:
我将标签设置为按钮,并用它代替<button> 或<input submit> 标签。
为了标识一个操作,我使用 href 属性,例如:
<a href='update'>Update</a>
<a href='delete'>Delete</a>
然后使用 jQuery: $('a[href="update"]').click(function() { ... });
效果很好。当给定链接充当表单上的提交按钮时,我还使用 href 属性作为“操作”参数的值。
现在问题 - 搜索引擎会因为我有盲链接而惩罚我吗? (我想是的)。
我该如何解决?改用#update?
我不能使用id 属性,因为可能有多个按钮执行相同的操作。
注意:点击处理程序可以使用类来连接,这很方便。所以我宁愿不使用id 将多个按钮连接到同一个处理程序。
<!-- inside a form -->
<a href='update' class='submit-button'>Update</a>
<!-- inside $(function() { .. });
$('a.submit-button').click(function() {
// 1. get href of the clicked link : href = $(this).attr('href');
// 2. add <input hidden> to the form: <input type='hidden' name='operation' value='<href>'/>
// 3. submit form : $(this).parents('form').submit();
});
【问题讨论】:
-
关于ajax页面和爬取的有趣文章(同样前提,JS接管“传统”浏览器事件):seomoz.org/blog/how-to-allow-google-to-crawl-ajax-content