是否可以专注于隐藏的输入字段? [英] Is it possible to focus on the hidden input field?

查看:214
本文介绍了是否可以专注于隐藏的输入字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们点击父元素时,如何触发隐藏的输入字段。当我使用隐藏字段不工作时。
这是我的html代码:

How to trigger the hidden input field when we click the parent element.When i use the hidden field is not worked. Here is my html code:

<table>
<th colspan="2">Date</th>
<td id="dateContainer" > currentData </td>
<td><input id="thedate" type="hidden" /></td>
<table>

jquery代码:

$(function(){
 $(this).click(function() {
 $(this).children().children().find('.datepicker-input').focus();
 });
});


推荐答案

嗯,我想我理解你的查询究竟是什么想要实现。

Well, I think I understood your query what exactly you want to achieve.

你想显示 datepicker ,而不显示容器。似乎不可能,因为每当你加载datepicker它需要一些CSS属性,如左,定位和所有。如果datepicker容器被隐藏,它会抛出异常。

you want to show the datepicker without visible container. It seems impossible because whenever you load datepicker it need some CSS property like left, positioning and all. and if datepicker container is hidden it will throw you exception.

下面是另一种可以实现的方式。创建一个空的html元素并添加日期选择器。

Below is another way by which you can achieve this. Create an empty html element and add date picker to it.

这是工作代码;更改您的html结构。

Here is the working code; change your html structure accordingly.

JSFiddle: http ://jsfiddle.net/vikash2402/8w8v9/2030/

JSFiddle: http://jsfiddle.net/vikash2402/8w8v9/2030/

$('#showDateContainer').click(function(){
$("#showDateItem").show && $("#showDateItem").show();
$('#showDateItem').datepicker({
        dateFormat: 'dd-mm-yy',
         onSelect: function(dateText) {
   		$('#dateContainer').text(dateText);
        console.log(dateText);
        $("#showDateItem").hide();
        }
        
    });
});
    
    

<link href="http://code.jquery.com/ui/1.8.21/themes/base/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

<script src="http://code.jquery.com/ui/1.8.18/jquery-ui.min.js"></script>



<div id="showDateContainer" type="button" >Click here to Shown Date</div>
<div id="showDateItem"> </div>
<br />
<br />
<div id="dateContainer" type="button" > currentData </div>

这将有助于您:)

Hoping this will help you :)

这篇关于是否可以专注于隐藏的输入字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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