Here is my Script:
这是我的脚本:
<script>
$('#myModal').on('show.bs.modal', function(e) {
var metrics_key = $('.createAlarm').val();
var metrics_label = $(".createAlarm option:selected").text();
// Now you have the key and label in variables.
// Write the key into the textfield.
$('#myModal input[name="name"]').val(metrics_key);
// Change the HTML of an element to the label.
$('#myModal label[for="priority"]').html(metrics_label);
});
var val = $('#priority').text();
$.post("/<pjtname>/createAlarm", { val : "val"});
</script>
I have a createAlarm class in a JSP page and clicking on a button from that page, pops up the following modal:
我在JSP页面中有一个createAlarm类,然后单击该页面上的一个按钮,弹出以下模式:
<!-- Modal- Create Alarm -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<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">Create Alarm</h4>
</div>
<form action="/CMPE283_Project2/createAlarm" method="post" id="addcard" class="form-horizontal" role="form">
<div class="modal-body" style="height: 170px;">
<div class="form-group" style="height: 30px;">
<label for="title" class="col-md-3 control-label">Name</label>
<div class="col-md-9">
<input type="text" class="form-control" name="alarmName">
</div>
</div>
<div class="form-group" style="height: 30px; margin-bottom:30px;">
<label for="title" class="col-md-3 control-label">Description</label>
<div class="col-md-9">
<textarea class="form-control" name="desc"></textarea>
</div>
</div>
<div class="form-group">
<label for="priority" id="priority" name="priority" class="col-md-3 control-label"> </label>
<div class="col-md-9">
<div class="col-md-3">
<select name="metric" class="form-control">
<option value="lessthan"><</option>
<option value="greaterthan">></option>
<option value="lessthanequalto"><=</option>
<option value="greaterthanequalto">>=</option>
</select>
</div>
<div class="col-md-3">
<input type="text" class="form-control" name="metricnum">
</div>
</div>
</div>
</div>
I want to pass the value of the label for priority to a servlet page. I tried:
我想将标签的值优先传递给servlet页面。我试过了:
String val = request.getParameter("val");
But, I am getting null value. Please help. Thanks.
但是,我的价值是空的。请帮忙。谢谢。
1 个解决方案
#1
$('#priority').text() to get value from html content .First Use post or get method inside Jquery to submit value to servlet. below link help to use get / post method. http://www.w3schools.com/jquery/jquery_ajax_get_post.asp
$('#priority')。text()从html内容中获取值.First在Jquery中使用post或get方法向servlet提交值。以下链接有助于使用get / post方法。 http://www.w3schools.com/jquery/jquery_ajax_get_post.asp
#1
$('#priority').text() to get value from html content .First Use post or get method inside Jquery to submit value to servlet. below link help to use get / post method. http://www.w3schools.com/jquery/jquery_ajax_get_post.asp
$('#priority')。text()从html内容中获取值.First在Jquery中使用post或get方法向servlet提交值。以下链接有助于使用get / post方法。 http://www.w3schools.com/jquery/jquery_ajax_get_post.asp