如何在PHP和jQuery中获取DIV id到POST FORM的值?

时间:2017-10-25 02:43:55

标签: php jquery

你好我想得到一个div形式的div的值。我正在使用POST。

这是我的代码,这个div也运行在jQuery上,值的变化取决于用户选择的颜色:

<div id="caption">Alumina Jade Metallic</div>

更新

这是div id = "caption"

动态转换的代码
   <span data-src="vios-color/vios_AJM.jpg" data-caption="Alumina Jade Metallic"><a href="#?" class = "label" ><img src="../../thumb/th-Alumina-Jade.png">  </a></span>
                            <span  data-src="vios-color/vios_B.jpg" data-caption="Black Metallic"><a href="#?" class = "label"><img src="../../thumb/th-Black.png"> </a></span>
                            <span  data-src="vios-color/vios_BRM.jpg" data-caption="Blackish Red Metallic"><a href="#?" class = "label"><img src="../../thumb/th-Black-Red.png"> </a></span>
                            <span  data-src="vios-color/vios_BMM.jpg" data-caption="Blue Metallic"><a href="#?"class = "label" ><img src="../../thumb/th-Blue-Metal.png"></a></span>
                            <span  data-src="vios-color/vios_FW.jpg" data-caption="Freedom White"><a href="#?" class = "label"><img src="../../thumb/th-Freedom-White.png"> </a></span>
                            <span  data-src="vios-color/vios_OM.jpg" data-caption="Orange Metallic"><a href="#?" class = "label"><img src="../../thumb/th-Orange-Metal.png"> </a></span>
                            <span  data-src="vios-color/vios_RMM.jpg" data-caption="Red Metallic"><a href="#?"class = "label" ><img src="../../thumb/th-Red-Metal.png">  </a></span>
                            <span  data-src="vios-color/vios_SM.jpg" data-caption="Silver Metallic"><a href="#?" class = "label"><img src="../../thumb/th-Silver-Metal.png">  </a></span>
                            <span  data-src="vios-color/vios_WP.jpg" data-caption="White Pearl"><a href="#?"class = "label" ><img src="../../thumb/th-White-Pearl.png"> </a></span>
                         </div>

这是我使用的jQuery:

$('.thumb span').each(function(){
  var _this = $(this);
  var src = _this.data("src");
  var text = _this.data("caption");
  _this.find('a').click(function(){
     $("#image").show( function() {
    $(".img img").attr("src", src);
    $("#caption").text(text);
     });
 });
});

我使用data-caption来更改div #caption

的数据

这是我的示例php POST:

$action = $_POST['action'];

    $fName = $_POST['form'][0]['fName'];
    $lName = $_POST['form'][0]['lName'];
    $address = $_POST['form'][0]['address'];
    $doBirth = $_POST['form'][0]['doBirth'];
    $city = $_POST['form'][0]['city'];
    $zipCode = $_POST['form'][0]['zipCode'];
    $email = $_POST['form'][0]['email'];
    $phone = $_POST['form'][0]['phone'];
    $remarks = $_POST['form'][0]['remarks'];

1 个答案:

答案 0 :(得分:0)

替代方案1:

你可以添加隐藏的输入,例如您<input type="hidden" name="colors" id="colors">内的<form> {},} {} {}} {}} {}} {}

例如:

<div>

然后在您的PHP上,您将检索$('#colorSelect').on('input',function() { var val = $('#colorSelect').val().join(); $('#caption').text(val); $('#colors').val(val); });

替代方案2:

使用jQuery $_POST['colors']函数,例如:

$.post()

您将在$.post('ProcessData.php',{colors:$('#caption').text(),data1:...,data2:...,etc},function(status) { alert(status); });

中检索<div>的文字