草庐IT

the-section-element

全部标签

javascript - Select2.js v4.0 : how set the default selected value with a local array data source?

通过使用select2.jsv4插件,当我使用本地数组数据作为源时,如何设置默认选择值?以这段代码为例vardata_names=[{id:0,text:"Henri",},{id:1,text:"John",},{id:2,text:"Victor",},{id:3,text:"Marie",}];$('select').select2({data:data_names,});如何设置id3为默认选中值? 最佳答案 $('.select').select2({data:data_names,}).select2("val",3);

javascript - lodash/js : Filtering values within an object based on regular expressions and getting the highest by comparison

对于下面的json[{"index":"xyz",...},{"index":"abc1234",...},{"index":"xyz",...},{"index":"abc5678",...}...我想分别过滤掉abc值和xyz值。我尝试了以下方法来获取值varx=_.filter(jsonData,function(o){return/abc/i.test(o.index);});它可以提供过滤后的输出。现在我想获得最高的abc值,如果有值abc123,abc444,abc999那么代码应该返回abc999。我可以使用lodash再次循环,但这是否可以在一次调用中完成-在同一个过滤

Javascript 无法通过 element.style.maxHeight 获取元素的最大高度

这个问题在这里已经有了答案:HowtogetanHTMLelement'sstylevaluesinJavaScript?(5个答案)关闭7年前。我正在用javascript制作一个简单的Accordion菜单。我希望能够通过cssmax-height和min-height值设置元素的紧凑高度和扩展高度。出于某种原因,当我尝试检索javascript中元素的最小高度和最大高度以用于动画目的时,我得到一个空字符串,而不是像它应该的那样,例如“500px”。最大高度值在css中设置,例如#id{最小高度:40px;最大高度:500px;都设置好了,但是当我在我的javascript中放置一

javascript - 是否有 'angular.element($0).scope()' 的 Angular 2 等价物

因此,出于我的罪过,我正在进行Angular2项目。我在旧的Angular1工作中一直使用angular.element($0).scope()来检查一个元素,并在开发工具中查看当时范围内的内容。这非常有用,Angular2中有类似的东西吗? 最佳答案 Augury是一个很好的建议。如果你想直接访问使用ng.probe($0)另见GetComponentReffromDOMelementHowtoaccessthe*angular2*components'datainthebrowser'sconsole?howtoaccessAn

javascript - 与 document.forms[0].elements[i].value; 等效的 jQuery 是什么?

什么是jquery等效于:document.forms[0].elements[i].value;?我不知道如何在jQuery中遍历表单及其元素,但想知道该怎么做。 最佳答案 通常的翻译是:input选择器:$("form:first:input").each(function(){alert($(this).val());//alertsthevalue});:first是因为您的示例提取了第一个,如果只有一个或您想要所有输入元素,只需使用:first离开。:inputselector适用于,,...您通常关心的所有元素都在这里。

javascript - Angular : How to access an element directive's scope in the controller

给定这个简单的Angular模块:angular.module('fixturesModule',[]).directive('clubfixtures',function(){"usestrict";return{restrict:'E',replace:true,transclude:true,scope:{club:"@club",max:"@max"},templateUrl:"ClubResultsTemplate.html",controller:function($scope,$http){$http.get("data.json").success(function(d

javascript - D3 分组条形图 : How to rotate the text of x axis ticks?

我使用的是分组条形图(http://bl.ocks.org/mbostock/3887051),但是x轴的文字很长,如附图所示。如何旋转文字?谢谢你。 最佳答案 可以找到合理的解决方案here结果是这样的:确保您完全理解这部分代码:svg.append("g").attr("class","xaxis").attr("transform","translate(0,"+height+")").call(xAxis).selectAll("text").style("text-anchor","end").attr("dx","-.8

JavaScript/jQuery : how do I get the inner window height?

比如...不包括地址栏、书签等的高度,只是查看空间。$(window).innerHeight()似乎不起作用。 最佳答案 使用.height()为此,如API中所述:Thismethodisalsoabletofindtheheightofthewindowanddocument.$(window).height();//returnsheightofbrowserviewport$(document).height();//returnsheightofHTMLdocument至于为什么.innerHeight()不工作:Thi

javascript - 脚本 600 错误 : Invalid target element for this operation

我有一个php网站,在FireFox和Chrome中运行良好,但在IE中完全崩溃。这只是抛出错误的脚本之一......SCRIPT600:此操作的目标元素无效。functionloadDeals(){$.get("modules/recommendations/viewrecommendations.php",{},function(response){document.getElementById("dealdata").innerHTML=response;});}它在设置innerHTML的行上抛出错误...知道为什么会这样吗? 最佳答案

javascript - window.onbeforeunload : Is it possible to get any details about how the window was unloaded?

我正在开发其中一个警告窗口,告诉用户他们可能有未保存的数据,但我只需要在他们离开页面时警告他们。目前它在刷新、回发等时这样做。我想知道是否有任何方法可以告诉页面是如何卸载的,或者以其他方式获取有关用户卸载页面的操作的更多详细信息。(欢迎使用jquery解决方案)。引用代码:window.onbeforeunload=function(){if(formIsDirty){formIsDirty=false;return"Areyousureyouwanttonavigateawayfromthispage?";}} 最佳答案 在bef