列表项将值传递给另一个页面php

时间:2016-06-29 18:20:22

标签: javascript php

我的代码有两个ul它工作正常如果我删除第二个ul我不想删除它我想要我的代码中的两个ul请帮我这个列表项的代码隐藏输入并传递到另一页



window.onload = function() {
  var form = document.getElementById('form-id');
  var col = form.querySelectorAll('li');
  for (var n in col)
    if (col[n] && col[n].nodeType == 1) {
      col[n].onclick = function(e) {
        document.getElementById('test').value = this.querySelectorAll('input[type="hidden"]')[0].value;
        form.submit();
      };
    }
};

<?php if($_SERVER['REQUEST_METHOD']=='GET' && isset($_GET['test'])) {
  echo'Test: '.$_GET['test'];
}
?>
&#13;
<form action="" id="form-id" method="get">
  <h1>Hidden values</h1>
  <ul class="nav navbar-nav" name="test">
    <!-- list elements -->
    <li><a href="index-2.html" class="home"><i class="fa fa-home"></i></a>
    </li>
    <li class="dropdown"><a href="javascript:void(0);" data-toggle="dropdown" class="dropdown-toggle">HANDCRAFTS<b class="caret"></b></a>
      <ul class="dropdown-menu" role="menu">
        <li class="full_width">
          <a>
            <input type="hidden" value="brasscraft" />Brass craft</a>
        </li>
        <li class="full_width">
          <a>
            <input type="hidden" value="wood" />wood</a>
        </li>
        <li class="full_width">
          <a>
            <input type="hidden" value="paintings" />paintings</a>
        </li>
        <li class="full_width">
          <a>
            <input type="hidden" value="marblecraft" />Marble craft</a>
        </li>
        <li class="full_width">
          <a>
            <input type="hidden" value="leathercraft" />Learther craft</a>
        </li>
      </ul>
    </li>
  </ul>
  <input type='hidden' id='test' name='test' />
</form>
&#13;
&#13;
&#13;

0 个答案:

没有答案