获取动态添加的值,在Bootstrap Modal中选择输入以显示/隐藏文本输入

时间:2019-01-19 22:58:50

标签: javascript jquery bootstrap-modal

我有一个Bootstrap Modal,使用jQuery在其中添加了Select下拉菜单,然后我需要获取该下拉菜单的值并显示或隐藏其他文本输入。

模态//points list List<MatOfPoint> squares = new ArrayList<MatOfPoint>(); private void findSquares(Mat image, List<MatOfPoint> squares){ squares.clear(); Mat smallerImg=new Mat(new Size(image.width()/2, image.height()/2),image.type()); Mat gray = new Mat(image.size(),image.type()); Mat gray0=new Mat(image.size(),CvType.CV_8U); // down-scale and upscale the image to filter out the noise Imgproc.pyrDown(image,smallerImg,smallerImg.size()); Imgproc.pyrUp(smallerImg, image,image.size()); // find squares in every color plane of the image for( int c = 0; c < 3; c++ ){ extractChannel(image, gray, c); // try several threshold levels for( int l = 1; l < N; l++ ){ //bez canny Imgproc.threshold(gray, gray0, (l+1)*255/N, 255, Imgproc.THRESH_BINARY); List<MatOfPoint> contours=new ArrayList<MatOfPoint>(); // find contours and store them all as a list Imgproc.findContours(gray0, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE); MatOfPoint approx=new MatOfPoint(); // test each contour for( int i = 0; i < contours.size(); i++ ){ // approximate contour with accuracy proportional // to the contour perimeter approx = approxPolyDP( contours.get(i), Imgproc.arcLength(new MatOfPoint2f(contours.get(i).toArray()), true)*0.02, true); double area = Imgproc.contourArea(approx); if(area > 5000){ if (approx.toArray().length == 4 && Math.abs(Imgproc.contourArea(approx)) > 1000 && Imgproc.isContourConvex(approx)) { double maxCosine = 0; Rect bitmap_rect = null; for (int j = 2; j < 5; j++) { // find the maximum cosine of the angle between joint edges double cosine = Math.abs(angle(approx.toArray()[j % 4], approx.toArray()[j - 2], approx.toArray()[j - 1])); maxCosine = Math.max(maxCosine, cosine); bitmap_rect = new Rect(approx.toArray()[j % 4], approx.toArray()[j - 2]); } // if cosines of all angles are small // (all angles are ~90 degree) then write quandrange // vertices to resultant sequence if( maxCosine < 0.3 ) squares.add(approx); } } } } } } 的一部分:

#testDetailModal

jQuery添加Select:

<div class="modal-body" id="modalBody">
    <p id="modalName"></p>
    <p id="modalTime"></p>
    <div class="col-md-12">
    </div>
    <p id="modalResponse"></p>
    <div class="col-md-12">
    <button type="button" class="btn btn-danger mt-2" id="statusButton">Change</button>
    </div>
</div>

如果选择了“失败”选项,我想显示$('<div class="soldClass col-md-12"><div class="form-group"> <label for="test-result" class="control-label">Update result:</label> <select class="form-control" name="test-result" id=resultSelect"> <option value="">Choose</option> <option value="pass">Passed</option> <option value="fail">Failed</option> </select></div></div> <div id="datePick" class="dateClass col-md-12"><div class="form-group"> <label for="test-date" class="control-label">Next test:</label> <input type="date" class="form-control" name="test-date"></div></div> <div class="resultClass col-md-12"> <button type="button" class="btn btn-danger mt-2" id="resultButton">Update</button> </div>').insertAfter( "#modalTime" ); div,我将其隐藏为:

#datePick

我无法获得Select的值来显示它,这是我尝试过的:

$('#testDetailModal').on('shown.bs.modal', function () {
  var nextDate = $('#datePick');
  nextDate.hide();
 });

希望有人可以为我指明正确的方向,我认为这与使用$('#testDetailModal').on('change','#resultSelect', function () { var resultOption = $('#resultSelect option:selected').val(); if(resultOption == 'fail') { nextDate.show(); //console.log(this.value); } else { nextDate.hide(); } }); 有关,但不确定如何去做。

0 个答案:

没有答案