通过单击带有JQuery的链接来填写输入字段 [英] Fill in Input Field by Clicking Link with JQuery

查看:80
本文介绍了通过单击带有JQuery的链接来填写输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

某人如何通过单击jQuery使用jquery在输入字段中填写一些文本?

How might someone fill in an input field with some text using jquery by clicking that text?

文本是动态生成的,因此无法提前知道该值.

The text is generated dynamically so the value is not know ahead of time.

例如:

<input id="a_input_id" type="text">
<a href="#" class="special_field_link">@r.SpecialField<a>

当某人单击链接文本字段的链接时,将填充@r.SpecialField

When someone clicks that link the text field with be populated with the value of @r.SpecialField

推荐答案

HTML:

<input id="a_input_id" type="text">
<a href="#" class="special_field_link">@r.SpecialField<a>

JS:

$(function(){
    $('.special_field_link').live('click', function() {
        $("#a_input_id").val($(this).html());
    });
});

此外,您可以使用.text()代替此答案中列出的.html():

Also, you can use .text() instead of .html() as listed in this answer: Fill in Input Field by Clicking Link with JQuery

运行示例: http://fiddle.jshell.net/s8nUh/

这篇关于通过单击带有JQuery的链接来填写输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆