[英]jquery Modal dialog Get value of input type text by id
我的PHP文件中有此代碼
$text .= ' <input type="text" name="prefix" value="'.htmlspecialchars($e1['prefix']).'" maxlength="20" class="inputListForm" id="prefix"/>';
我想獲取輸入類型文本的值
這是我的代碼:
var prefix = $('#prefix').get(0).value;
console.log(prefix);
我也嘗試document.getElementById("prefix");
但還是沒有結果
如果對要獲取值的代碼使用jQuery語法會更好:例如:
$(document).ready(function(){
var prefix = $('#prefix').val();
console.log(prefix);
});
確保添加了jquery庫,並且不會與此沖突。
如果要在按鈕單擊選項上獲得此值,則必須將操作事件稱為“波紋管”:
$(document).ready(function(){
$("#button").click(function (e) {
var prefix = $('#prefix').val();
console.log(prefix);
});
});
在這種情況下,您還需要在jQuery語法之間獲得此值。 希望您能找到解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.