Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery selected=selected_Jquery - Fatal编程技术网

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