Tag: 数组

我如何拼接我的arrays?

我有一个collections夹function,但希望用户能够删除它们。 这就是它的样子: 所以我想要实现的是每个调用remove函数的项下的“Remove”链接,因此删除了该实体。 这是我的JS: function updateFavourite(video) { document.getElementById(‘favourite’).onclick = function () { if ($.grep(myfavourite, function (item) { return item[“id”] == video[“id”]; }).length == 0) { blacklist] = true; myfavourite.push(video); var html = “” + “” + “{2}” + “by {3}” + “{4} | {5} views” + “”; $(“#myfavourite”).prepend(html.format(video[“thumbnail”], video[“id”], video[“title”], video[“uploader”], video[“length”], video[“views”])); } } […]

尝试使用javascript中的对象属性动态工作

我试图弄清楚这是否合理,但最多会出现语法错误。 所以我想知道它是否可能。 我拥有的是一个对象(仅限示例) var myObj = { something1_max:50, something1_enabled:false, something1_locked:true, something2_max:100, something2_enabled:false, something2_locked:true, something3_max:10, something3_enabled:true, something3_locked:true } 而我想通过一个函数做的事情就是再做一次,例如总结一下…… function displayDetails(theScope, obj) { console.log(obj.[theScope]_max); } (function(){displayDetails(‘something3’, myObj);})() 因此,当调用displayDetails()时,我在本例中可以看到的范围是该范围的最大值。 在示例的控制台日志中,我希望看到10

在不同的输入文本上生成随机数并确保显示的随机数是唯一的

我正在尝试使用JQuery创建一个JavaScript代码段,该代码段具有不断变化的随机数,并将显示在不同的文本框中。 但是,我无法弄清楚如何使数字显示每个文本框的不同值。 我怎么能做到这一点? 这是我到目前为止的JavaScript代码: var pcount = $(“.pcount”); for(var i= 0; i < pcount.length; i++){ var n = []; var element = pcount.eq(i); setInterval(function() { n[i] = 10 + Math.floor(Math.random(Number($( ".pcount" ).val())) * 10); $('.pcount').val(n[i]); }, 1000);} 以下是文本框的HTML代码:

Javascript – 生成范围中的随机数,不包括某些数字

基本上我正在创建一个网格并在其上绘制点,并且没有两个点可以在完全相同的位置[(3,4)与(4,3)不同]。 y坐标必须在2和7之间(所以2,3,4,5,6,7),x坐标必须在1和7之内。我有一个getRandom函数(可以在下面看到)生成一个最小和最大范围之间的随机数。 这是我到目前为止所拥有的。 var xposition = []; var yposition = []; var yShouldBeDifferentThan = [] function placeRandom() { for (s=0; s<xposition.length ; s++ ) { if (xposition[s] == x) { // loops through all numbers in xposition and sees if the generated x is similar to an existing x yShouldBeDifferentThan.push(yposition[s]); //puts the corresponding y coordinate […]

如何从数组数组中提取值

我有一个数组存储。 我需要从这个数组中提取特定的值。 例如,allarray包含数组列表allarray = [Array [3],Array [3],Array [3]]是存在于其中的三个数组。 0:数组[3] 0:“a1”1:“b1”2:“c1” 1:数组[3] 0:“a2”1:“b2”2:“c2” 3:数组[3] 0:“a3”1:“b3”2:“c3” 我需要从上面的数组中提取这个c1,c2和c3并显示在警告框中。 谁能告诉我怎么做到这一点? 我试过$ .each但不幸的是不起作用。 有人可以吗?

Processing.js图片数组无法正常显示

我正在尝试从我的数据库中获取图片路径数据并在处理草图上显示它,因此这是Javascript文件: function send() { function setPath(d) { var s = d; var processingInstance; if (!processingInstance) { processingInstance = Processing.getInstanceById(‘canvas’); } processingInstance.change(s); } var variable = 2; $.ajax({ method: “POST”, tupe: “POST”, url: “take.php”, data: ({val: variable}), success: function (data) { $(‘#msg’).html(data); setPath(data); }, }); } 这是PHP文件: $value) { echo ” $value”; } // echo $im; […]

如何在外部网页上选择并打开某个class级的随机链接?

我有: var linksInCategory = document.$(‘.CategoryTreeLabel’).href); var randomLinkArray = Array(linksInCategory); 我需要转到外部网页并在该文档中搜索类别为.CategoryTreeLabel任何项目并获取附加的href 。 见下文。 randomLinkArray只是我查询的链接数组。 function goThere(link) { var the_url = randomLinkArray[Math.floor(Math.random()*randomLinkArray.length)]; var new_window = window.open(the_url,”new_window”,”menubar, resizeable. location, toolbar, status, scrollbars”); } the_url从数组randomLinkArray随机选择的链接的值。 这将在新窗口中打开the_url 。 当用户单击该按钮时,应将它们带到Wikipedia页面,该页面是从我们查询的页面中的链接数组中随机选择的(现在在按钮中设置为src=”” )。 我不确定的事情是: 我需要转到外部网页并搜索该文档以查找具有.CategoryTreeLabel类的任何项目并获取附加的href – 由于.CategoryTreeLabel ,我不能在JavaScript中执行此操作 – 任何技巧? 我的数组的参数在function goThere()调用时随机href的公式 在哪里放置url “http://en.wikipedia.org/wiki/Category:Sports”我想从这里获取.CategoryTreeLabels并创建从中选择随机URL的数组 抱歉继续,希望能够清楚。 谢谢!

使用模式窗体更新数组中的对象并显示更新的详细信息

我正在尝试通过单击编辑按钮来更新外部对象。 它会弹出一个弹出窗口,我可以在其中输入新信息,然后相应地更新用户。 但不知何故它似乎没有用。 它只是触发页面刷新,根本没有任何反应。 你能帮帮我解决这个问题吗? var myData = [{ company: “ABC”, url: “www.abc.com”, type: “internal” }, { company: “CDE”, url: “www.cde.com”, type: “internal” }, { company: “DEF”, url: “www.def.com”, type: “external” }, { company: “EFG”, url: “www.efg.com”, type: “internal” }, { company: “FGH”, url: “www.fgh.com”, type: “external” }]; $(‘#createData’).click(function() { createDisplay(); }); function createDisplay() { […]

是否可以在url jquery中发送对象

data.push({ name: name, age: age, address: address, contactnumber: contactnumber }); var url = ‘../reports/student.php?data=’+data; window.open(url, ‘_blank’); ../reports/student.php?data=[object%20Object] 上面是我想要发送到另一个页面的对象,所以我可以检索它并在下一页上使用它来生成报告。 url看起来像上面那个我不确定这是否可能,如果可能的话,我如何获得对象中每个数据的值。如果不可能请指出正确的方向任何想法是ap

如何访问jquery ajax函数返回的数组字符串

我有以下代码,用onkeyup事件搜索在搜索框中键入的字符。 $(“#keywords”).keyup(function () { var kw = $(“#keywords”).val(); if (kw != ”) { var url = “” + kw; $.ajax({ type: “POST”, url: url, datatype: “json”, success: function (data) { **alert(data);** $.each(data,function(ptitle, category){ $(“#results”).html(”+ptitle+’: ‘+category+”); } } }); }else{ $(“#results”).html(“”); return false; } }); 在上面的代码中,当我提醒data它显示以下数组字符串。 {“pcode”:”22″,”category”:”NightTalk”,”ptitle”:”HourlyNightTalk”} 我似乎无法访问pcode , category和ptitle就像我在下一行中所做的那样。 (提醒后)请帮助我如何访问这三个!