隐藏div单击NO单选按钮

时间:2016-09-29 12:09:05

标签: javascript jquery html

我在代码段中解决了我的问题,但是当我在我的网站上使用它时,如果我点击extension UIImage { public func imageRotatedByDegrees(degrees: CGFloat, flip: Bool) -> UIImage { let radiansToDegrees: (CGFloat) -> CGFloat = { return $0 * (180.0 / CGFloat(M_PI)) } let degreesToRadians: (CGFloat) -> CGFloat = { return $0 / 180.0 * CGFloat(M_PI) } // calculate the size of the rotated view's containing box for our drawing space let rectZero = CGPoint(dictionaryRepresentation: CGRect.zero as! CFDictionary) let rotatedViewBox = UIView(frame: CGRect(origin: rectZero!, size: size)) let t = CGAffineTransform(rotationAngle: degreesToRadians(degrees)); rotatedViewBox.transform = t let rotatedSize = rotatedViewBox.frame.size // Create the bitmap context UIGraphicsBeginImageContext(rotatedSize) let bitmap = UIGraphicsGetCurrentContext() // Move the origin to the middle of the image so we will rotate and scale around the center. bitmap!.translateBy(x: rotatedSize.width / 2.0, y: rotatedSize.height / 2.0); // // Rotate the image context bitmap!.rotate(by: degreesToRadians(degrees)); // Now, draw the rotated/scaled image into the context var yFlip: CGFloat if(flip){ yFlip = CGFloat(-1.0) } else { yFlip = CGFloat(1.0) } bitmap!.scaleBy(x: yFlip, y: -1.0) CGContextDrawImage(bitmap, CGRectMake(-size.width / 2, -size.height / 2, size.width, size.height), CGImage) let newImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return newImage! } } No按钮radio没有关闭,那么当我在我的网站上使用它时在控制台中工作甚至没有错误。 请任何人有类似这样的其他解决方案。感谢。

更新了完整代码: 现在不在这里工作也有两个pro div应该在pro div关闭并在No

打开



YES

function ShowHideDiv() {
  var chkYes = document.getElementById("chkYes");
  var pro = document.getElementsByClassName("pro");
  for (var i = pro.length - 1; i >= 0; i--) {
    pro[i].style.display = chkYes.checked ? "block" : "none";
  }
  
}

$('input[type="radio"]').change(function () {
    $(this).nextAll('.pro').toggle(this.value == 'Yes');
}).change();




2 个答案:

答案 0 :(得分:1)

这可能是你的答案,ShowHideDiv()函数,因为它有点加倍制作一个javascript函数并使用jQuery做同样的事情。

另外要小心这个



  
$("input[name='isprocontact']").change(function () {
if(this.value == 'Yes'){
    $('.pro').show();
}else{
    $('.pro').hide();
}
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container-fluid">
          <form id="add_form" method="post" enctype="multipart/form-data" action="<?php echo site_url('contacts/save'); ?>">
    <div class="row">
      <div class="col-lg-6">
      
                <h4>English</h4>
              <div class="form-group">
              <label>Category:</label>
                  <select id="contact_type" class="chosen-select required" multiple tabindex="6" name="contact_type[]">
                    <option value=""></option>
                      <?php foreach ($getSubCat as $key => $value) {?>
                      <option value="<?php echo $value['Sub_Category_Name'] ?>"><?php echo $value['Sub_Category_Name'] ?></option>
                      <? } ?>
                  </select>
              </div>

              <div class="form-group">
                  <input class="form-control required" name="name" id="name" placeholder="Business Name">
              </div>
              <div class="form-group">
                  <input class="form-control required" name="number1" id="number1" placeholder="Contact Number 1">
              </div>
              <div class="form-group">
                  <input class="form-control required" name="number2" id="number2" placeholder="Contact Number 2">
              </div>
              <div class="form-group">
                  <input class="form-control required" name="owner" id="owner" placeholder="Owner Name">
              </div>

              <div class="form-group">
                  <textarea class="form-control required" rows="3"  name="address"  id="address" placeholder="Address"></textarea>
              </div>       
          <div>
  <div class="form-group ">
      <select id="location"   class="form-control  required" name="location" >
        <option value="">Select Location</option>
        <?php
        foreach ($getLoc as $key => $value) {
          $location = $value['location_name']; ?>
            <option  value="<?php echo $location; ?>"> <?php echo $location; ?> </option>
        <?php } ?>
      </select>
      </div>

 
      </div>

<div class="form-group">
      <div class="typediv">
          <label><input type="radio" name="type" value="1"> Free</label>
          <label><input type="radio"  name="type" value="2"> Paid</label>
          <label><input type="radio"  name="type" value="3"> Emergancy</label>
      </div>                                
  </div>
      <div class="2 box"></div>
      <div class="3 box"></div>

  <div class="form-group 2 box" style="display:none">
              
       <input type="date" class="required" name='durability' id="datepicker" value="" >
     
 
            </div>
            
            <div class="form-group isprocontactdiv">
            <label>Is Pro Contact </label>
                Yes<input type="radio" id="chkYes" name="isprocontact" value="Yes" >
                No<input type="radio" id="chkNo" name="isprocontact" value="No" checked="">
            </div>

        <div class="pro" style="display: none;" >
            <div class="form-group">
                <input class="form-control required" name="email" placeholder="Email"  >
            </div>
            <div class="form-group" >
                <input type="file" name="userfile">
            </div>
            <div class="form-group">
                <textarea class="form-control required"  id="description" name="description" rows="3" placeholder="Description" ></textarea>
            </div>
            <div class="form-group">
                <textarea class="form-control required" id="services" rows="3" name="services" placeholder="Services" ></textarea>
            </div>
        </div>
           
    </div>
    <div class="col-lg-6">
            <h4>Marathi</h4>
            <div class="form-group">
                <input class="form-control required" name="name_marathi" id="name_marathi" placeholder="व्यवसाय">
            </div>
            <div class="form-group">
                <input class="form-control required" name="contact_owner_marathi" id="contact_owner_marathi" placeholder="मालकाचे नाव">
            </div>
            <div class="form-group">
                <textarea class="form-control required" name="contact_address_marathi" id="contact_address_marathi" rows="3" placeholder="पत्ता"></textarea>
            </div>
            <div class="pro" style="display:none">
                <div class="form-group">
                    <textarea class="form-control required" name="description_marathi" id="description_marathi" rows="3" placeholder="सविस्तर माहिती"></textarea>
                </div>
                <div class="form-group">
                    <textarea class="form-control required" rows="3" name="service_marathi" id="service_marathi" placeholder="सुविधा"></textarea>
                </div>
            </div>    
    </div>
    </div>
    <!-- /.row -->
     <button type="submit" class="btn btn-success">Submit</button>
            <button type="reset" class="btn btn-warring">Reset</button>
            </form>

</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

你的问题不是很清楚,但如果你想点击形式,你可以像那样处理,例如:

var $chkNo = $('#chkNo');
var $chkYes = $('#chkYes');
var $proform = $('.pro');

$chkNo.on('click',function(){
  $proform.css('display','none') // or you can play with visibility property
});
$chkYes.on('click',function(){
  $proform.css('display','block') // or you can play with visibility property
});