我有一个隐藏的文本框,当用户单击产品订单按钮时存储数据,同时将其存储在 cookie 中。
因此,当用户访问另一个页面时,比如说结帐页面,他们需要填写表格,他们之前选择的项目列表将自动列在文本区域内。
现在它在文本区域内填充数据,但它不是一个很好的布局。这是它的样子。
Product1 Product2 Product3 Product4 Product5 Product6
我怎样才能组织起来,让它像这样显示?
Product1
Product2
Product3
Product4
Product5
..........
下面是我的代码。
<div id="hide" style="display: none;">
<textarea id="myContent2" name="myContent2"><?php echo $_COOKIE['content']; ?> </textarea>
<a onClick="addContent('myDiv2', document.getElementById('myContent2').value); setCookie('content', document.getElementById('myContent2').value, 1);">
<br><br>
<div id="myDiv2" style="font-weight: bold;"></div>
<a onclick="javascript:alert('<?php echo $_COOKIE['content']; ?>')">Here</a>
</div>
<script type="text/javascript">
function addContent(divName, content) {
document.getElementById(divName).innerHTML += "<br>" + content;
}
</script>
<script type="text/javascript">
function setCookie(c_name,value,expiredays) {
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function getCookie(c_name) {
if (document.cookie.length>0) {
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1) {
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length;
var cookieContent = unescape(document.cookie.substring(c_start,c_end));
document.getElementById('myDiv2').innerHTML = cookieContent;
}
}
}
getCookie('content');
</script>