jQuery selected=selected
我有jQuery selected=selected,jquery,Jquery,我有在文件chat_select.php中。 我每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);
代码>在文件chat_select.php中。
我每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)
那么这个呢?:$(“#用户选项[value=“+val+”]”)attr(“选定的”、“选定的”)代码>所选是一个属性:$('my_select')。prop('Selected')
将属性“Selected”设置为true
每次刷新前,将当前选定的选项保存在变量中,刷新完成后,使用jquery重新选择该选项
$('#YourSelectBox').change(function() {
var x = this.value;
$(this).data('saved', x);
})
然后通过执行以下操作检索保存的状态
$('#YourSelectBox').data('saved')
注意:刷新页面将清除您保存的所有数据。FYI您可能需要添加一个true标志:$('my_select').prop('selected',true)
强制JQuery应用属性。从1.6.1开始,您还可以使用类似attr的prop