Tag: 变量

jQuery在div中提取文本但不在p标签中

在下面的代码中,我想将一个变量放在div的文本中,但不是p标签内的内容: I want to grab this text From a cool person – My Date goes here – A Review 另外我想只拉它的前250个字符,如果可能的话!

通过Jquery AJAX传递PHP变量

我正在尝试学习Jquery AJAX函数,但我正在努力研究如何将PHP变量传递到我的主文档中。 这就是我目前所拥有的: var refreshId = setInterval(function() { $.ajax({ url: “test.php”, dataType: “json”, //the return type data is jsonn success: function(data){ // <— (data) is in json format $('#testdiv').html(data.test1); $('#testdiv').append(html(data.test2)); //parse the json data } }); }, 1000);

动态jQuery变量名称

我想获取li ID属性的值(它将是一个userID),并将其用作字符串的一部分,我最终将其用作变量名称的一部分。 我将使用此变量名来创建一个数组。 我理解基础知识,但似乎无法找到jQuery / javascript的正确组合来实现这种魔力。 jQuery(‘#user-list li’).click(function() { var userID = jQuery(this).attr(“id”); // i want to add the word array to the end of userID var theVariableName = userID + “Array”; // I want to use this variable to create an array var theVariableName = new Array(); // I want to continue to use […]

jQuery的ajax成功函数的额外参数

我正在使用以下代码获取XML文件: function getMaps(){ toLoad = loadMaps.length; for (var i = 0; i < loadMaps.length; i++){ $.ajax({ type: "GET", url: loadMaps[i], dataType: "xml", success: processMap }); } } 哪个工作正常,但我想给processMap另一个参数(即loadMaps [i],存储加载的xml的名称) 我不知道如何在不诉诸全局变量的情况下做到这一点,这不是我想要的。

javascript setInterval()和Variable Scope

好的,我在这里看了几个问题但标题相同,但仍无法找到问题的解决方案。 我正在研究一个基本的javascript倒计时器,我一直在更新变量的值。 a = 100; var i = setInterval( function(){ timer( a ); }, 1000 ); function timer( a ){ console.log( a ); if( a < 1 ){ console.log( 'Reaching Stop' ); clearInterval( i ); return; } a -= 1; } 当我将a的值递减-1时, console.log( a )每次应减少1,即 100 99 98 …… 但是console.log( a )总是给100 新手到这里javascript请温柔。 谢谢。

Javascript变量不起作用。 为什么?

我不是在了解javascript中的变量。 我试图在localScroll函数发生之前更改/计算“offset”(使用变量“theOffset”),或者更优选地在调整窗口大小时。 下面的实例都不起作用,接受“// initialize offset”。 如何更改“$ .localScroll”中的变量“theOffset”? jQuery(function( $ ){ //initialize offset var windowWidth = $(window).width(); if (windowWidth < 900) { theOffset = 0; } else { theOffset = ($(window).width() – 900) / -2; } $(window).resize(function() { //calculate offset var windowWidth = $(window).width(); if (windowWidth < 900) { theOffset = 0; } else { theOffset […]

优化代码只定义变量一次,代码仅在变量处于变更函数时才起作用,而变更外部的代码重新定义?

很确定我知道解决方案…会写.on(’更改’,’加载’,函数(){}正确吗? < – 测试不起作用?所以我能够解决你的问题:) Sushanth – && adeneo都提出了很好的解决方案,这是优化代码的一个很好的教训…选择哪个答案很难,但我知道这会帮助我重新思考我的写作方式。如果没有这个论坛,我不知道我做了什么,我必须在大学里学习这些东西。 这纯粹是出于好奇心和提高我的技能的问题,也是让你们有机会展示你对jQuery的知识。 还要防止任何草率的写作。 我有一个基于无线电的开关盒,标记看起来像这样,id和开/关值是由我的数组中的值与PHP生成的… //This color is the background of the toggle, I need jQuery to change this color based on the state on/off //this is my on value generated by the array // I create this input because I have multiple checkboxes that have the ID _moon_ARRAYVALUE_area1 […]

将xml节点的属性设置为变量

我试图获取XML节点的属性的值,并使用JQuery将其设置为变量。 这可能吗? 我想将7366的customerId属性设置为变量供以后使用,如下所示: $customerId = customer id from xml node attribute; 这可能吗? 如果您需要进一步澄清,请与我们联系。 谢谢!

Jquery / JavaScript – 将Ajax jSONP响应存储到变量中

我正在使用JSONP获得ajax请求的结果,没有任何问题。 这是我的代码 function TestJSONP() { $.ajax({ url: “https://www.sample.com/api/users.json?account_api_key=0000&unique_install_id=0000&email_address=test@test.com&locale_id=en-US&operating_system_version=6.1.7601.65536&operating_system_architecture=64&outlook_version=2013&version=0.0.5.0”, // the name of the callback parameter, as specified by the YQL service jsonp: “callback”, // tell jQuery we’re expecting JSONP dataType: “jsonp”, // tell YQL what we want and that we want JSON data: { q: “select title,abstract,url from search.news where query=\”cat\””, format: “json” }, // […]

jQuery YQL SELECT FROM rss变量

所以我有一个变量“woeid”,我正试图为“w”的价值投入 – $.YQL(“select * from rss where url=’http://weather.yahooapis.com/forecastrss?w=”+woeid”‘”,function(data){ 为什么它不起作用? 编辑:整个脚本 – $(document).ready(function() { $.YQL = function(query, callback) { var encodedQuery = encodeURIComponent(query.toLowerCase()), url = ‘http://query.yahooapis.com/v1/public/yql?q=’ + encodedQuery + ‘&format=json&callback=?’; $.getJSON(url, callback); }; $.YQL(“select place.woeid from flickr.places where lat=34.45 and lon=-118.54”, function(data) { var w=data.query.results.places.place; woeid = w.woeid }); $.YQL(“select * from rss where url=’http://weather.yahooapis.com/forecastrss?w=” + […]