2014-10-05 51 views
0

值我有92价值<input type="hidden" name="location">的onclick价值,形成HTML

  • 我可以使用下拉菜单或其他方法,但它很难选择下拉
  • ,所以我显示的行和科拉姆所有值

我怎样才能使ONCLICK值以形成输入????

  • ,我需要显示所选择的值

如何我已经通过单击方法隐藏表单值以形成值

USA   india  china 
austria  japan  koera 
上点击

以形成值

回答

1
<span class="country">USA</span> 
<span class="country">India</span> 

<input type="hidden" name="country" id="country" /> 

然后jQuery的

$('.country').on('click', function() { 
    $('#country').val($(this).text()); 
}); 

如果您需要与国家代码,而不是名称来填充表单,你可以这样做:

<span class="country" data-code="us">USA</span> 
<span class="country" data-code="in">India</span> 

<input type="hidden" name="country" id="country" /> 

然后jQuery

$('.country').on('click', function() { 
    $('#country').val($(this).data('code')); 
}); 
0

Depends中在HTML上。

的jQuery:

$('select').on('change', function(){ 
    $(this).closest('form').find('input:hidden').click(); 
}); 
+1

如何将它的工作 – 2014-10-05 17:51:44