[英]How to get values from dynamically generated page and its form fields
I am building an android application using PhoneGap and jQuery Mobile. 我正在使用PhoneGap和jQuery Mobile构建一个android应用程序。
I am having problem fetching the values of form fields in jQuery of a dynamically generated page (data-role="page") which contains the form and fields. 我在获取包含表单和字段的动态生成页面(data-role =“ page”)的jQuery中获取表单字段的值时遇到问题。
My code is like this: 我的代码是这样的:
<script type="text/javascript">
$page('<div data-role="page" data-theme="b" id="editKeeperForm">
<div data-role="content">
<form method="POST" action="editKeeper" data-ajax="false">
<input type="text" name="name2" id="name" data-clear-btn="true"
value='+keeperRecord.fld_keeperName+'>
<input type="submit" id="save" value="Save">
</form>
</div>
</div>');
$page.appendTo($.mobile.pageContainer);
$page.page();
$.mobile.changePage( $page );
$(document).on('click', '#editKeeperForm #save', function () {
console.log($("#name").val());
});
</script>
Any help is much appreciated. 任何帮助深表感谢。
When you do this: 执行此操作时:
$("#save").click(function () {
console.log($("#name").val());
});
Do you get the same issue? 你有同样的问题吗?
Since this is a dynamically generated page you may have to use 由于这是一个动态生成的页面,因此您可能必须使用
$("#editKeeperForm").enhanceWithin()
after you generate it. 生成它之后。 This is often the case with dynamically generated things in jQuery Mobile. jQuery Mobile中动态生成的东西通常是这种情况。
找到了解决此问题的方法$(this).find(“#name”)。val();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.