通过 Jquery 从单击的锚标记填充标题上的隐藏表单元素值

发布于 2024-08-28 17:04:58 字数 164 浏览 1 评论 0原文

嘿大家。我试图根据单击的链接在隐藏表单元素上设置一个值。我认为解决此问题的最佳方法是将锚标题属性作为特定隐藏表单元素的值传递。此隐藏表单元素值需要根据单击的最新链接进行更新。我在谷歌上搜索了 jQuery 片段来实现这一点,但似乎找不到一个很好的起点来运行它。

任何帮助表示赞赏!我正在学习,学习。

Hey all. I'm trying to set a value on a hidden form element based on a link that is clicked. I figure the best way to go about this is to pass along the anchor title attribute as the value for a particular hidden form element. This hidden form element value will need to be updated depending on the latest link that is clicked. I've scoured google for jQuery snippets to achieve this but can't seem to find a good starting point to run with this.

Any help is appreciated! I'm learning, learning.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半世蒼涼 2024-09-04 17:04:58

如果没有任何 HTML,它只是猜测,但一般方法是:

$('a').click(function(e) {
     e.preventDefault(); // <-- don't follow the link
     $('#id-of-hidden-field').val($(this).attr('title'));        
});

这会将 click 处理程序绑定到任何链接(当然您应该以某种方式限制此设置)并将其放在 title< /code> 属性插入隐藏字段(由 ID 引用)。

参考:click()val(), attr(), <代码>preventDefault()

Without any HTML, it is just guessing, but a general approach would be:

$('a').click(function(e) {
     e.preventDefault(); // <-- don't follow the link
     $('#id-of-hidden-field').val($(this).attr('title'));        
});

This binds a click handler to any link (of course you should restrict this set somehow) and puts their the title attribute into a hidden field (that is referenced by an ID).

Reference: click(), val(), attr(), preventDefault()

如果没有 2024-09-04 17:04:58

请尝试这个:

$("a").click(function(){$("#hdnField").val($(this).attr("title");return false;});

HTH

Please try this:

$("a").click(function(){$("#hdnField").val($(this).attr("title");return false;});

HTH

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文