我想在 html 表单中为下拉菜单设置一个 cookie,当刷新页面时,我应该得到存储在下拉框中 cookie 中的值。我为输入框编写了如下代码:
<script type="text/javascript">
function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
</script>
<input name="order_num" type="text" size="10" value="<?php if(isset($_COOKIE["order_num"])) echo $_COOKIE["order_num"];?>" onblur="setCookie(this.name,this.value,60*60*2)" />
以类似的方式,我想为下拉框编写 cookie。下拉菜单的代码如下:
<select name="quality" onChange="setCookie('quality',this.value,60*60*2)" selected="" >
<option >Select One</option>
<option value="good" selected="good">Good</option>
<option value="ok" selected="ok">A bit low but we can use it</option>
...
</select>
<input type="checkbox" name="proceed_opt[]" value="I will upload new Image" onblur="setCookie(this.name,this.value,60*60*2);>
Insert Option "I will upload new Image"</td></tr>
<input type="checkbox" name="proceed_opt[]" value="I approve this sample for a Night Light" onblur="setCookie(this.name,this.value,60*60*2);>
Insert Option "<font face="Arial, Helvetica, sans-serif" size="2">I approve this sample for a Night Light</font>"
任何人都帮我设置cookie....