我正在使用以下引导代码来显示一个模态,现在我想从输入字段中获取值。我尝试了很多方法,但未能使用javascript获取数据。
<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Forgot Password ?</h4>
</div>
<div class="modal-body">
<p>Enter your employee id below to reset your password.</p>
<input type="text" name="getId" placeholder="Employee id" autocomplete="off" class="form-control placeholder-no-fix">
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-default" type="button">Cancel</button>
<button class="btn btn-primary" btn="submt" type="button">Submit</button>
</div>
</div>
</div>
</div>
$(document).ready(function () {
var btnSubmit = $(element).parent().prev().find("#submt");
$(btnSubmit).click(function()
{
//var ids = $('getId').val();
var ids = $(element).parent().prev().find("#getID");
alert(ids);
$.ajax({
url:'rtrv_pass.php',
type:'post'
//data:{uid:},
});
});
});
答案 0 :(得分:1)
尝试使用以下代码,它可以帮助您解决问题。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Forgot Password ?</h4>
</div>
<div class="modal-body">
<p>Enter your employee id below to reset your password.</p>
<input type="text" name="getId" placeholder="Employee id" autocomplete="off" class="form-control placeholder-no-fix">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary">Submit</button>
</div>
</div>
</div>
</div>
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
答案 1 :(得分:1)
我刚修改了点击事件代码..
Jquery的:
$('#btnSubmit').click(function () {
var textFieldVal = $('input[name="getId"]').val();
$.ajax({
url: 'rtrv_pass.php',
type: 'post'
//data:{uid:},
});
});
答案 2 :(得分:0)
您可以使用jquery代码获取输入文本字段的值
var input_value = $("#myModal").find('input').val();
答案 3 :(得分:0)
在提交按钮中添加唯一ID:
<button id="uniqueId" class="btn btn-primary" btn="submt" type="button">Submit</button>
$(document).ready(function () {
$('#uniqueId').click(function()
{
var ids = $(this).closest('.modal-dialog').find('input[name="getID"]');
alert(ids);
$.ajax({
url:'rtrv_pass.php',
type:'post'
//data:{uid:},
});
});
我建议你在跳转到代码之前首先阅读关于类,id,dom,编程的一些内容