在div id

时间:2017-11-02 06:11:00

标签: javascript php html echo

这里是index.php中的BUTTON,用于打开Modal表单;

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<a href="#myModal" data-toggle="modal" value="#01" name="btn" class="button2 btn btn-success model_open" data-btnval = "#01" aria-hidden="true" data-dismiss="modal" >form</a>

这是获取当前按钮值的脚本;

$(document).on("click", ".model_open", function () {
var btnval = $(this).data('btnval'); 

   $(".modal-body #btnval").text( btnval );
$('#hiddenid').val(btnval );
});

这是模态表格,回显按钮值“#01”

<!-- Modal header starts -->                                                
                    <div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal" class="modal fade">
                          <div class="modal-dialog">
                              <div class="modal-content">
                                  <div class="modal-header1" style="padding:10px 15px;">
                                <button type="button" class="close" data-dismiss="modal" >&times;</button>
                                    <h4><span class="glyphicon glyphicon-pencil"></span>MODAL FORM</h4>
                            </div>
                                <div class="modal-body" style="padding:10px 10px;">
<!-- Modal header ends -->

            <div id="btnval"></div> <!-- Echo the button value "#01" -->

<!-- Modal Application form starts -->  
                 <div class="modal-body">

                        <div class="modal-body">
                        <form action="confirmation.php" method="get" enctype="multipart/form-data">

                    <!-- First Name Filed Starts -->
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label for="name">NAME</label>
                                <input type="text" class="form-control" name="name" id="name" required="required" placeholder="Name">
                            </div>
                        </div>

            <input type="submit" class="btn btn-success pull-right" value="NEXT">

单击“模态表单”中的“下一步”按钮时,将进入第二页,将Modal表格中的所有信息与按钮值“#01”一起显示;

<form id="main-contact-form1"  style="background-color: #f0f8ff; padding: 20px;" class="contact-form1" name="contact-form1" method="post" action="sendappli.php" role="form">   


                      <div class="label-field-pair">
                        <label>ID</label>
                        <input class="form-control" id='id' name='id' value='<?php echo $_GET["btnval"]; ?>'  />
                      </div>

          <div class="label-field-pair">
                        <label>Name</label>
                        <input class="form-control" id='name' name='name' value='<?php echo $_GET["name"]; ?>'  />
                      </div>

在发送到我的电子邮件地址之前检查提供的信息。

问题:我无法从<div id="btnval">获取“btnval”的值,需要有一个NAME来获取其值并在第二页将其回显到<?php echo $GET[posible name of btnval];?/> ???? / p>

enter image description here

4 个答案:

答案 0 :(得分:2)

请参阅以下代码

var div= document.getElementById('btnval');
div.setAttribute('name', 'sample');

或:

document.getElementsByTagName("DIV")[0].setAttribute("name", "sample");

答案 1 :(得分:1)

试试这段代码,

1)index.php

AuthenticationApi authApi = new AuthenticationApi();
LoginInformation loginInfo = authApi.login();

// parse first account ID (user might belong to multiple accounts) and baseUrl
String accountBaseUrl = loginInfo.getLoginAccounts().get(0).getBaseUrl();
String[] accountDomain = accountBaseUrl.split("/v2");`

2)demo.php

<div id="btnval">Hello This My Div</div>

<script type="text/javascript">
    var div = document.getElementById('btnval');
    div.setAttribute('name', 'sample');
</script>

答案 2 :(得分:0)

使用load方法将div从first page转换为second page

$("#div").load("/firstpage.html #btnval");

在第二页

上使用div加载id

答案 3 :(得分:0)

您可以改用数据属性。

<div id="btnval" data-name="sample">

然后你可以使用jquery将它作为url参数传递给另一个页面然后使用它,

<?php echo $_GET["sample"]; ?>