gpt4 book ai didi

javascript - 保存链接分配值以及转到其他页面

转载 作者:行者123 更新时间:2023-11-28 07:31:43 24 4
gpt4 key购买 nike

我有一个表,用户可以在其中添加数据,我还有输入字段和保存链接。在我的保存链接中,如果我单击它..我会在输入字段转到其他页面之前为其分配值。但是当它转到另一个页面并且我回显输入字段的值时,我得到了空值,就像空值一样。

这是我的代码:对于表:

<table class="table " id="memberTB">
<thead>
<tr>
<th >First Name</th>
<th >Middle Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<tr id="first">
<td><span class="edit"></span></td>
<td><span class="edit"></span></td>
<td><span class="edit"></span></td>
</tr>
</tbody>
<button type="button" class="btn btn-link" id="addrow">
<span class="fa fa-plus"> Add new row</span>
</button>
</table>
<input type="text" name="list" id="list"/>
<br>
<a class="btn" id="savebtn">Save</button>
<a href="#" class="btn" id="resetbtn">Reset</a>

对于 js 来说:

$('#savebtn').click(function() {

var cells = 3; //number of collumns
var arraylist = []
var x=0;

$('tbody tr',$('#memberTB')).each(function(){
var cell_text = '';
for(var i = 0 ; i < cells ; i++){
if(i==2){
cell_text =cell_text+$(this).find('td').eq(i).text()+":";
}else{
cell_text =cell_text+$(this).find('td').eq(i).text()+",";
}
}
arraylist.push(cell_text);
});
document.getElementById("list").value =arraylist;
document.getElementById("savebtn").href="<?php echo site_url('test/save');?>";
}

当我在 save()test.php 中回显它时,我什么也没得到,如下所示:

echo $this->input->post('list');

最佳答案

您只是重定向页面。所以你不会从帖子中获得任何值(value)。如果您想通过post方式获取值,则需要通过表单提交该值。

 <form id='save_form' method="post" action="<?php echo site_url('test/save');?>">   
//add your html codes
//<table ..... and others
<a class="btn" href="#" id="savebtn">Save</button> //add # to href for save button
</form>

现在是你的js

$('#savebtn').click(function() {

//js codes that you wrote
//just replace the following line
//document.getElementById("savebtn").href="<?php echo site_url('test/save');?>";
$('#save_form').submit();
}

关于javascript - 保存链接分配值以及转到其他页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29058513/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com