我有chat_select.php.文件中的<select name="users"> ... </select>我每8个sekunds刷新一次到#chatSelect。
这是一个刷新文件chat.php
var auto_refresh = setInterval(
function () {
$('#chatSelect').load('php/refresh/chat_select.php?hodnota='+$('select.user option:selected').val()).fadeIn();
}, 8000);怎么啦?我需要这个,如果我从select中选择一些值,它将保持不变(selected=selected)。
那么这个呢?:$("#user option[value=" + val + "]").attr("selected", "selected");
发布于 2011-08-13 23:39:30
Selected是一个属性:$('my_select').prop('selected')将属性"selected“设置为true。
http://api.jquery.com/prop/
发布于 2011-08-13 23:51:02
在更改时保存复选框的状态
$('#YourSelectBox').change(function() {
var x = this.value;
$(this).data('saved', x);
})然后通过以下操作检索保存的状态
$('#YourSelectBox').data('saved')注意:刷新页面将清除您保存的任何数据。
发布于 2011-08-13 23:42:07
每次刷新之前,将当前选定的选项保存在变量中,刷新完成后,使用jquery重新选择该选项。
https://stackoverflow.com/questions/7053972
复制相似问题