0

嗨,我正在尝试使用 Jquery 添加动态输入,但是当我尝试获取代码时它不起作用

codeigniter 中的代码捕获所有 POST 但少于 jquery 添加的代码

这是代码:

<script type="text/javascript">
 $(document).ready(function(){
    var value = parseFloat($("#subtotal").val());
    $('.subtotal').html(value);
    $('#subtotal').val(value);
    $('input[name="phprop"]').change(function(event){
        if($('input[name="phprop"]:checked').val() == 'Yes'){
            $('#sections').show();
        }else if($('input[name="phprop"]:checked').val() == 'No'){ $('#sections').hide();}
        });
        $('input[name="xsst"]').change(function(event){
        if($('input[name="xsst"]:checked').val() == 'Yes'){
            $('#xtraphotos').show();
            $('<input type="text"  name="extraid'+i+'" id="extraid'+ i +'" style="width:80px;margin-left:4px;"/>').appendTo('#xtrabox');
            var num = value + 9.95;
            value = parseFloat(num.toFixed(2));
            $('.subtotal').html(value);
            $('#subtotal').val(value);
            $('#extrass').val(i);               i++;

        }else if($('input[name="xsst"]:checked').val() == 'No'){ 
            $('#xtraphotos').hide();
            $('#xtraphotos input[type="text"]').remove();
            var num = value - 9.95 * (i - 1);
            value = parseFloat(num.toFixed(2));
            $('.subtotal').html(value);
            $('#subtotal').val(value);
            $('#extrass').val(0);
            i = 1;
            }
        });
        var scntDiv = $('#xtrabox');
        var i = 1;

    $('#addScnt').live('click', function() {
            $('<input type="text"  name="extraid'+i+'" id="extraid'+ i +'" style="width:80px;margin-left:4px;"/>').appendTo(scntDiv);
            num = value + 9.95;
            value = parseFloat(num.toFixed(2));
            $('.subtotal').html(value);
            $('#subtotal').val(value);
            $('#extrass').val(i);
            i++;                
            return false;
      });       
 });
 </script>

这是HTML

 <div style="margin-left: 50px;">
<label><b>Do you need more photos for your web?</b> </label>Yes<input type="radio"     name="xsst" id="xsst" value="Yes"/>No<input type="radio" name="xsst" id="xsst" value="No"/> (Each aditional photo has a cost of <b>$9.95</b>)
    <div id="xtraphotos" style="display:none;"><a href="#" id="addScnt">Add another picture box</a><div id="xtrabox"></div></div></div> 

这是 Codeigniter 代码:

 if($_POST['extrass'] !=0){
        for($i=1;$i<=$_POST['extrass'];$i++){
            $names = "extraid".$i;
            $extras .= $_POST[$names];
            if($i!=$_POST['extrass']){
            $extras .= "-";
                }
        }

这是完整的 HTML(只是表单部分):

  <?php echo form_open_multipart(base_url() . 'purchase/confirmation')?>
    <p style="float:left">Image ID of the Photos for your Website</p><div style="float:left;margin: 13px 0 0 110px;width: 450px;"><?php 
   if($idtype == 4){$x=3;}elseif($idtype == 1){$x=5;}elseif($idtype == 2){$x=10;}elseif($idtype == 3){$x=13;}
    for($i=1;$i<=$x;$i++){?><input type="text"  name="ssid[]" id="ssid_<?=$i?>" value="" style="width:80px; margin-left:4px;"/><?php }?></div>
 </div>
  <div style="margin-left: 50px;">
  <label><b>Do you need more photos for your web?</b> </label>Yes<input type="radio"  name="xsst" id="xsst" value="Yes"/>No<input type="radio" name="xsst" id="xsst" value="No"/> (Each aditional photo has a cost of <b>$9.95</b>)
  <div id="xtraphotos" style="display:none;"><a href="#" id="addScnt">Add another picture box</a><div id="xtrabox"></div></div></div>


  <br />
    <div id="choose_your_template" style="background-image:url(<?=base_url()?>images/step_4.png)"><div style="padding-left:5px; float:left">
<span style=" position: relative; top: 14px; left: 210px; font-size: 18px; color: gray; ">Step 4: Do you have Photos? Upload the pictures for your website.</span></div>

    </div>
     <div style="margin-left: 50px;">
     <label>Do you have photos of your property? </label>Yes<input type="radio" name="phprop" id="phprop" value="Yes"/>No<input type="radio" name="phprop" id="phprop" value="No"/><br />
   <div id="sections" style="display:none;">
    <p>Upload the photos in the theme that they should be used. The photos should be in jpge.format. Otherwise the system will not accept. them.</p><br/>
   <?php 
    if($idtype == 4){$x=1;}elseif($idtype == 1){$x=3;}elseif($idtype == 2){$x=4;}elseif($idtype == 3){$x=5;}
   for($i=1;$i<=$x;$i++){?>
      <label>Section</label><select name="section[]" id="section"><option value="">Choose Section</option><option value="home">Home</option><option value="about-us">About Us</option><option value="contact-us">Contact Us</option></select><?php   for($j=1;$j<=4;$j++){?><input type="file"  name="userphoto<?=$i?><?=$j?>" /><?php }?><br />   <br />
  <?php }?>
     <p>I certify that the photos that i am uploading for the website development are of my entire property and that I have all the copyrights.</p></div>
   </div><br />


   <input type="hidden" id="domain" name="domain" value="<?=$domain?>" />
  <input type="hidden" id="payment_plan" name="payment_plan" value="<?=$poption?>" />
  <?php if($ownamedomain){?>
  <input type="hidden" name="ownamedomain" id="ownamedomain" value="<?=$ownamedomain?>" />
  <?php }?>
   <input type="hidden" name="idtype" id="idtype" value="<?=$idtype?>" />
  <input type="hidden" name="templateid" id="templateid" value="<?=$templateid?>" />
 <input type="hidden" name="extrass" id="extrass" value="0" />
 <input type="hidden" name="subtotal" id="subtotal" value="<?=$subtotal?>" />
 <div style="padding-left:45px; padding-top:15px;">
 <hr style=" width: 868px; margin: 0 0 16px; "/>
 <div align="center">
 <p>Subtotal: USD$<span class="subtotal"><?=$subtotal?></span> </p></div>
 </div>
 <div style="background:url(<?=base_url()?>images/bottombar.png) no-repeat;display: block;height: 16px;margin: 0 36px 10px;width: 902px;"></div>
 <input type="submit" name="continue" id="continue"/><input type="button" value="Back" onClick="history.back();" class="back">
  </div>
4

1 回答 1

0

你的 HTML 有标签形式吗?

当您没有将表单元素放在表单中时,onload,一些browser添加表单以纠正代码语法......但是当您使用DOM添加nes元素时,也许这些元素不包含在这个表单中......

于 2012-11-16T01:37:41.890 回答