通过表单发送锚标记值。

时间:2022-11-27 18:27:31

Is it possible to send anchor tag value through a form?

是否可以通过表单发送锚标记值?

<a href=# id="link">Some Value</a>

MY application/ use for this is to be used in a web form, in which the options are listed in a ul li a format, rather than a select option format.

我的应用程序/用途是在web表单中使用,其中选项以ul li a格式列出,而不是选择选项格式。

Is there any workaround to this, without using select option format? JS or jQuery solutions preferred.

在不使用select选项格式的情况下,是否有解决方案?最好是JS或jQuery解决方案。

edit: I've found this answer, but it involves ajax. Is there a pure JS/ jQuery method possible?

编辑:我找到了这个答案,但是它涉及到ajax。是否可能有纯JS/ jQuery方法?

2 个解决方案

#1


1  

I think you may consider to use <input type="hidden">.

我想你可以考虑使用

<form>
    <a href=# id="link">Some Value</a>
    <input type="hidden" name="link" value="Some Value"/>
</form>

#2


1  

With jQuery-

jQuery -

jQuery(document).ready(function($) {
    var current_url = window.location.href;
    var hidden_value = "<input type='hidden' name='url' value='"+current_url+"'>";
    $(YourFormSelector).append(hidden_value);
});

#1


1  

I think you may consider to use <input type="hidden">.

我想你可以考虑使用

<form>
    <a href=# id="link">Some Value</a>
    <input type="hidden" name="link" value="Some Value"/>
</form>

#2


1  

With jQuery-

jQuery -

jQuery(document).ready(function($) {
    var current_url = window.location.href;
    var hidden_value = "<input type='hidden' name='url' value='"+current_url+"'>";
    $(YourFormSelector).append(hidden_value);
});