Get selected value in dropdown list using JavaScript?

How do I get the selected value from a dropdown list using JavaScript? I tried the methods below but they all return the selected index instead of the value: var as = document.form1.ddlViewBy.value; var e = document.getElementById("ddlViewBy"); var strUser = e.options[e.selectedIndex].value; //This is one of the simplest form by (Narendra Kottamidde) : var value = document.getElementById("dd

使用JavaScript在下拉列表中获取选定的值?

如何使用JavaScript从下拉列表中获取选定的值? 我尝试了下面的方法,但它们都返回选定的索引而不是值: var as = document.form1.ddlViewBy.value; var e = document.getElementById("ddlViewBy"); var strUser = e.options[e.selectedIndex].value; //This is one of the simplest form by (Narendra Kottamidde) : var value = document.getElementById("ddlViewBy").value; 如果你有一个看起来像这样的select元素: &l

jquery getting all dropdown values

I have dropdown <select> with id my_dropdown . I allow multi-select. I know how to pull the selected value(s) using jquery: var values = $('#my_dropdown').val(); This will return an array of values if I select multiple. I also need to get all the values in the dropdown regardless of what is selected. How can I use jquery similarly to get all the values in the dropdown given that id?

jquery获取所有下拉值

我使用id my_dropdown下拉<select> 。 我允许多选。 我知道如何使用jQuery获取选定的值: var values = $('#my_dropdown').val(); 如果我选择多个,这将返回一个数组值。 无论选择什么内容,我还需要获取下拉列表中的所有值。 我如何使用jquery类似地获取所有在给定的id下拉列表中的值? 感觉如何: var values = []; $('#my_dropdown option').each(function() { values.push( $(this).attr('value') ); });

How do I get the YouTube video ID from a URL?

I want to get the v=id from YouTube's URL with JavaScript (no jQuery, pure JavaScript). Example YouTube URL formats http://www.youtube.com/watch?v=u8nQa1cJyX8&a=GxdCwVVULXctT2lYDEPllDR0LRTutYfW http://www.youtube.com/watch?v=u8nQa1cJyX8 Or any other YouTube format that contains a video ID in the URL. Result from these formats u8nQa1cJyX8 你不需要为此使用正则表达式。 var video_

如何从网址获取YouTube视频ID?

我想通过JavaScript从YouTube的URL中获取v=id (没有jQuery,纯JavaScript)。 YouTube网址格式示例 http://www.youtube.com/watch?v=u8nQa1cJyX8&a=GxdCwVVULXctT2lYDEPllDR0LRTutYfW http://www.youtube.com/watch?v=u8nQa1cJyX8 或者是其他任何包含网址中的视频ID的YouTube格式。 来自这些格式的结果 u8nQa1cJyX8 你不需要为此使用正则表达式。 var video_id = window.location.search.split('v=')[1]; var am

Find body tag in an ajax HTML response

I'm making an ajax call to fetch content and append this content like this: $(function(){ var site = $('input').val(); $.get('file.php', { site:site }, function(data){ mas = $(data).find('a'); mas.map(function(elem, index) { divs = $(this).html(); $('#result').append('' + divs + ''); }) }, 'html'); }); The problem is that when I ch

在ajax HTML响应中查找body标签

我正在做一个Ajax调用来获取内容并附加这样的内容: $(function(){ var site = $('input').val(); $.get('file.php', { site:site }, function(data){ mas = $(data).find('a'); mas.map(function(elem, index) { divs = $(this).html(); $('#result').append('' + divs + ''); }) }, 'html'); }); 问题是,当我更换a body我什么都没有(没有错误,只是没有html

Google Hosted Libraries is unnecessarily using cache breakers

I am using the following code on our dashboard to refresh it constantly without flicker How can I refresh a page with jQuery? : <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script> setTimeout(function() { $.ajax({ url: "", context: document.body, success: function(s,x){ $(this).html(s); }

Google托管图书馆不必要地使用缓存破坏者

我在仪表板上使用下面的代码来不断刷新它而不会出现闪烁如何使用jQuery刷新页面? : <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script> setTimeout(function() { $.ajax({ url: "", context: document.body, success: function(s,x){ $(this).html(s); } }); }, 4000); </script> 但是,由于某

Clearing localStorage in javascript?

有没有什么办法可以重置/清除JavaScript中的浏览器localStorage? 使用这个来清除localStorage: localStorage.clear(); 如果要从用户的本地存储中删除特定项目或变量,可以使用localStorage.removeItem("name of localStorage variable you want to remove"); window.localStorage.clear(); //try this to clear all local storage

在javascript中清除localStorage?

有没有什么办法可以重置/清除JavaScript中的浏览器localStorage? 使用这个来清除localStorage: localStorage.clear(); 如果要从用户的本地存储中删除特定项目或变量,可以使用localStorage.removeItem("name of localStorage variable you want to remove"); window.localStorage.clear(); //try this to clear all local storage

How do I store an array in localStorage?

This question already has an answer here: Storing Objects in HTML5 localStorage 25 answers localStorage only supports strings. Use JSON.stringify() and JSON.parse() . var names = []; names[0] = prompt("New member name?"); localStorage.setItem("names", JSON.stringify(names)); //... var storedNames = JSON.parse(localStorage.getItem("names")); The localStorage and sessionStorage can only han

如何将数组存储在localStorage中?

这个问题在这里已经有了答案: 在HTML5 localStorage中存储对象25个答案 localStorage只支持字符串。 使用JSON.stringify()和JSON.parse() 。 var names = []; names[0] = prompt("New member name?"); localStorage.setItem("names", JSON.stringify(names)); //... var storedNames = JSON.parse(localStorage.getItem("names")); localStorage和sessionStorage只能处理字符串。 您可以扩展默认的存储对象来处理数组

Stringify (convert to JSON) a JavaScript object with circular reference

I've got a JavaScript object definition which contains a circular reference: it has a property that references the parent object. It also has functions that I don't want to be passed through to the server. How would I serialize and deserialize these objects? I've read that the best method to do this is to use Douglas Crockford's stringify. However, I'm getting the follow

将具有循环引用的JavaScript对象字符串化(转换为JSON)

我有一个包含循环引用的JavaScript对象定义:它有一个引用父对象的属性。 它还具有我不想传递给服务器的功能。 我将如何序列化和反序列化这些对象? 我读过这样做的最好方法是使用Douglas Crockford的stringify。 但是,我在Chrome中收到以下错误: TypeError: Converting circular structure to JSON 代码: function finger(xid, xparent){ this.id = xid; this.xparent; //other attributes } function

How do I update each dependency in package.json to the latest version?

I copied package.json from another project and now want to bump all of the dependencies to their latest versions since this is a fresh project and I don't mind fixing something if it breaks. What's the easiest way to do this? The best way I know of now is to run npm info express version then update package.json manually for each one. There must be a better way. { "name": "myprojec

如何将package.json中的每个依赖项更新为最新版本?

我从另一个项目复制了package.json,现在想要将所有依赖关系都打包到最新版本中,因为这是一个全新的项目,我不介意解决它的问题。 最简单的方法是什么? 我现在知道的最好方法是运行npm info express version然后手动为每个npm info express version更新package.json。 一定会有更好的办法。 { "name": "myproject", "description": "my node project", "version": "1.0.0", "engines": { "node": "0.8.4",

JavaScript: when I pass array from iframe function the array lose his type!

I have an iframe in a form. The iframe contains some info that I want deliver to the form parent by instance of Array. The problem: the Array instance loses it's type and becomes an object! The iframe function: function getIDS2() { return new Array(); } The parent call code: alert(top.frames["sup_search"].getIDS2() instanceof Array); Of course the answer for the alert is false... So, I

JavaScript:当我从iframe函数传递数组时,数组会丢失他的类型!

我有一个表单中的iframe。 iframe包含一些我想通过Array实例传递给父窗体的信息。 问题:数组实例失去它的类型,并成为一个对象! iframe功能: function getIDS2() { return new Array(); } 家长电话代码: alert(top.frames["sup_search"].getIDS2() instanceof Array); 当然,警报的答案是错误的...所以,我可以通过这样做来解决它: var arr = []; for(var i =0; i < SuppliersIDs.length; i+=1) { arr.push(S