使用jquery获取文本字段的值(文本文件包含日期)

时间:2015-04-27 05:14:36

标签: javascript jquery

我想在文本字段中获取date的值。 我的HTML代码:

  $("#sample tr td").after('<td><input type="text" id="datepicker"/></td>').queue(function() {
    $('#datepicker').datepicker();
      $(this).dequeue();
 });

js file:

{{1}}

我想提醒给文本框的日期。  的jsfiddle:

fiddle

6 个答案:

答案 0 :(得分:2)

警告改变价值,如:

 <a href="food-option=0&talent-option=0,123,456">

DEMO

答案 1 :(得分:1)

您可以在选择器的任何操作中使用.val()来选择datepicker元素以获取其值。

同样不是after()方法是同步方法,所以不需要使用queue()

$("#sample tr td").after('<td><input type="text" id="datepicker"/></td>');
$('#datepicker').datepicker();

$('button').click(function(){
    alert($('#datepicker').val())
})

演示:Fiddle

答案 2 :(得分:1)

jQuery("#slMinor_Title option:selected").text()

答案 3 :(得分:0)

$("#sample tr td").after('<td><input type="text" id="datepicker"/></td>').queue(function() {
  $('#datepicker').datepicker({
    onSelect: function(date) {
      alert("You selected : " + date);
    }
  });
  $(this).dequeue();
})
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.3/jquery-ui.min.js"></script>



<table id="sample">
  <tr>
    <td>
      Date
    </td>
  </tr>

我不太明白这个问题,但我认为你的意思是!!

答案 4 :(得分:0)

$("#sample tr td").after('<td><input type="text" id="datepicker"/></td>');
$('#datepicker').datepicker({
  onSelect: function(date) {
    alert("You selected : " + date);
  }
});
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.3/jquery-ui.min.js"></script>



<table id="sample">
  <tr>
    <td>
      Date
    </td>
  </tr>

这也有效......

答案 5 :(得分:0)

试试这个......为我工作!

$(document).ready(function(){
$(document).on("change","input#datepicker", function(){
    if($(this).val()!="") {
      alert($(this).val());
    }
}); });
相关问题