Javascript从下拉菜单中记住所选选项值

Javascript从下拉菜单中记住所选选项值,javascript,load,selected,Javascript,Load,Selected,做了一点研究,我现在知道我必须编写所选选项的cookie。然后读取cookie以检索值 我发现了一个类似的问题,但无法从答案中找出如何实现代码 下拉记忆选择测试 选择流 朱曼吉乔 当链接攻击 多克布鲁 卡伦迈韦夫 夜间清醒 恐怖事件0001 动漫总部 电影湾 恐怖片 111aaachark电影 我设法创建了一个下拉菜单,可以更改iframe SRC。我只需要它来记住他们在刷新或浏览器退出时选择的内容。为此,当用户选择值时,请将该值存储到浏览器的本地/或会话存储中,当用户首次重新打开时,请检

做了一点研究,我现在知道我必须编写所选选项的cookie。然后读取cookie以检索值

我发现了一个类似的问题,但无法从答案中找出如何实现代码


下拉记忆选择测试
选择流
朱曼吉乔
当链接攻击
多克布鲁
卡伦迈韦夫
夜间清醒
恐怖事件0001
动漫总部
电影湾
恐怖片
111aaachark电影

我设法创建了一个下拉菜单,可以更改iframe SRC。我只需要它来记住他们在刷新或浏览器退出时选择的内容。

为此,当用户选择值时,请将该值存储到浏览器的本地/或会话存储中,当用户首次重新打开时,请检查本地存储是否具有该值。如果是,请使用jquery选择该值

// Store
localStorage.setItem("lastname", "Smith");
// Retrieve
document.getElementById("result").innerHTML = localStorage.getItem("lastname");
您可以查看如何在W3上使用本地存储:

编辑:

在这里找到完整的代码

<iframe id="stream_iframe" marginwidth="0" marginheight="0" width="854" height="480" scrolling="no" allowtransparency="true" frameborder="0" framespacing="0" name="stream_iframe" src="http://vaughnlive.tv/embed/video/moviebay"></iframe> 

<form> 
<select name="options" onchange="callMe(this);" id="selectMovie">
<option>SELECT STREAM
<option value="https://streamup.com/rooms/jumanjijoes-Channel/plugins/video/show?startMuted=false">Jumanjijoe</option>
<option value="http://vaughnlive.tv/embed/video/whenlinkattacks">Whenlinkattacks</option>
<option value="https://streamup.com/rooms/docblus-Channel/plugins/video/show?startMuted=false">Docblu</option> 
<option value="http://vaughnlive.tv/embed/video/karenwaifu">Karenmaiwaifu</option>
<option value="http://vaughnlive.tv/embed/video/ninjatart">Nightsanity</option>
<option value="http://vaughnlive.tv/embed/video/frightfest0001">Frightfest0001</option> 
<option value="http://vaughnlive.tv/embed/video/anime_hq">Anime HQ</option>
<option value="http://vaughnlive.tv/embed/video/moviebay">MovieBay</option>
<option value="http://vaughnlive.tv/embed/video/freakyfetish101">Horror Movie</option>
<option value="http://vaughnlive.tv//embed/video/111aaacharkmovies">111aaacharkmovies </option> 
</select>
</form>
<script>
function callMe(obj){
localStorage.setItem("selectedStream",obj.options[obj.selectedIndex].value);
document.getElementById('stream_iframe').src = obj.options[obj.selectedIndex].value;
}
document.getElementById("stream_iframe").src = localStorage.getItem("selectedStream");
document.getElementById("selectMovie").value = ""+localStorage.getItem("selectedStream")+"";
</script>

选择流
朱曼吉乔
当链接攻击
多克布鲁
卡伦迈韦夫
夜间清醒
恐怖事件0001
动漫总部
电影湾
恐怖片
111aaachark电影
函数callMe(obj){
localStorage.setItem(“selectedStream”,obj.options[obj.selectedIndex].value);
document.getElementById('stream_iframe').src=obj.options[obj.selectedIndex].value;
}
document.getElementById(“stream_iframe”).src=localStorage.getItem(“selectedStream”);
document.getElementById(“selectMovie”).value=“+localStorage.getItem(“selectedStream”)+”;

我知道我必须存储值,但问题是我不知道表单会是这样吗?//存储localStorage.setItem(“selectedStream”、“value”);//检索document.getElementById(“stream_iframe”).innerHTML=localStorage.getItem(“selectedStream”);我已经添加了完整的代码。将其复制到html文件并在浏览器上运行。感谢您浏览代码,我现在更好地理解了。谢谢。src在第一次运行时变为null。
<iframe id="stream_iframe" marginwidth="0" marginheight="0" width="854" height="480" scrolling="no" allowtransparency="true" frameborder="0" framespacing="0" name="stream_iframe" src="http://vaughnlive.tv/embed/video/moviebay"></iframe> 

<form> 
<select name="options" onchange="callMe(this);" id="selectMovie">
<option>SELECT STREAM
<option value="https://streamup.com/rooms/jumanjijoes-Channel/plugins/video/show?startMuted=false">Jumanjijoe</option>
<option value="http://vaughnlive.tv/embed/video/whenlinkattacks">Whenlinkattacks</option>
<option value="https://streamup.com/rooms/docblus-Channel/plugins/video/show?startMuted=false">Docblu</option> 
<option value="http://vaughnlive.tv/embed/video/karenwaifu">Karenmaiwaifu</option>
<option value="http://vaughnlive.tv/embed/video/ninjatart">Nightsanity</option>
<option value="http://vaughnlive.tv/embed/video/frightfest0001">Frightfest0001</option> 
<option value="http://vaughnlive.tv/embed/video/anime_hq">Anime HQ</option>
<option value="http://vaughnlive.tv/embed/video/moviebay">MovieBay</option>
<option value="http://vaughnlive.tv/embed/video/freakyfetish101">Horror Movie</option>
<option value="http://vaughnlive.tv//embed/video/111aaacharkmovies">111aaacharkmovies </option> 
</select>
</form>
<script>
function callMe(obj){
localStorage.setItem("selectedStream",obj.options[obj.selectedIndex].value);
document.getElementById('stream_iframe').src = obj.options[obj.selectedIndex].value;
}
document.getElementById("stream_iframe").src = localStorage.getItem("selectedStream");
document.getElementById("selectMovie").value = ""+localStorage.getItem("selectedStream")+"";
</script>