在编辑模式下,文本框呈现为:
<input value="10/05/2017" name="purchasedate" id="purchasedate" class="form-control required valid" aria-required="true" type="text">
在jQuery中我试图获取:
function validateform(){
var purchasedate = $("#purchasedate").val().trim();
alert(purchasedate);
if(!checkValidDate(purchasedate)){
displayDateErrorMessage("Purchase Date");
return false;
}
}
显示为空白!
请帮忙!
答案 0 :(得分:2)
尝试使用
$('#elementid').attr('value');
答案 1 :(得分:0)
您需要将函数作为回调函数添加到$(document).ready()
$(document).ready(function () {
var purchasedate = $("#purchasedate").val().trim();
alert(purchasedate);
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input value="10/05/2017" name="purchasedate" id="purchasedate" class="form-control required valid" aria-required="true" type="text">
&#13;
答案 2 :(得分:0)
在文本框中写 onChange
<input onChange="validateform()" value="10/05/2017" name="purchasedate" id="purchasedate" class="form-control required valid" aria-required="true" type="text">