[英]Get the value of text field (text fidle contains date) using jquery
我想在文本字段中獲取日期的值。 我的HTML代碼:
<table id="sample">
<tr>
<td>
Date
</td>
</tr>
</table>
js文件:
$("#sample tr td").after('<td><input type="text" id="datepicker"/></td>').queue(function() {
$('#datepicker').datepicker();
$(this).dequeue();
});
我想提醒輸入文本框的日期。 的jsfiddle:
提醒更改值,例如:
$(document).on("change","input", function(){
if($(this).val()!="") {
alert($(this).val());
}
});
//In below code, you can replace input[type=text] with classname/id of input field.
$('input[type=text]').on('change', function() {
alert($('input[type=text]').val());
});
$("#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>
我沒有完全明白這個問題,但我想你是這個意思!!
$("#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>
這也將起作用...
試試這個...為我工作!
$(document).ready(function(){
$(document).on("change","input#datepicker", function(){
if($(this).val()!="") {
alert($(this).val());
}
}); });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.