Questions tagged «javascript»

有关在ECMAScript(JavaScript / JS)及其各种方言/实现(不包括ActionScript)中进行编程的问题。此标记很少单独使用,但最常与标记[node.js],[jquery],[json]和[html]关联。

13
NG模型不会更新控制器值
可能是愚蠢的问题,但是我的html表单带有简单的输入和按钮: <input type="text" ng-model="searchText" /> <button ng-click="check()">Check!</button> {{ searchText }} 然后在控制器中(从routeProvider调用模板和控制器): $scope.check = function () { console.log($scope.searchText); } 为什么单击按钮后,视图在控制台中正确更新但未定义? 谢谢! 更新:似乎我实际上已经解决了该问题(之前不得不提出一些解决方法),方法是:只需将我的属性名称从更改searchText为search.text,然后$scope.search = {};在控制器中定义空对象,瞧……不知道为什么它起作用虽然;]


16
如何使用jQuery与.reset()方法重置表单
单击重置按钮时,我有可以重置表单的工作代码。但是,在我的代码变长之后,我意识到它不再起作用了。 <div id="labels"> <table class="config"> <thead> <tr> <th colspan="4"; style= "padding-bottom: 20px; color:#6666FF; text-align:left; font-size: 1.5em">Control Buttons Configuration</th> </tr> <tr> <th>Index</th> <th>Switch</th> <th>Response Number</th> <th>Description</th> </tr> </thead> <tbody> <form id="configform" name= "input" action="#" method="get"> <tr><td style="text-align: center">1</td> <td><img src= "static/switch.png" height="100px" width="108px"></td> <td id="small"><input style="background: white; color: black;" type="text" value="" …

9
如何通过把手中的索引访问访问数组项?
我正在尝试在把手模板内的数组中指定项的索引: { people: [ {"name":"Yehuda Katz"}, {"name":"Luke"}, {"name":"Naomi"} ] } 使用这个: <ul id="luke_should_be_here"> {{people[1].name}} </ul> 如果上述方法不可行,我该如何编写一个可以访问数组中特殊项目的助手?

2
不是jQuery中的类选择器
是否有一个简单的选择器表达式,可以不选择具有特定类的元素? <div class="first-foo" /> <div class="first-moo" /> <div class="first-koo" /> <div class="first-bar second-foo" /> 我只想获取前三个div并尝试 $(div[class^="first-"][class!="first-bar"]) 但这可以接收所有内容,因为最后一个div包含的内容不止第一条。有没有办法在这样的表达式中使用占位符?像这样 $(div[class^="first-"][class!="first-bar*"]) // doesn't seem to work 还有其他选择器可能会有所帮助吗?



12
根据对象属性删除数组元素
我有一个像这样的对象数组: var myArray = [ {field: 'id', operator: 'eq', value: id}, {field: 'cStatus', operator: 'eq', value: cStatus}, {field: 'money', operator: 'eq', value: money} ]; 如何根据其属性删除特定的? 例如,我将如何删除以'money'作为字段属性的数组对象?

27
解决承诺一个接一个(即按顺序)?
考虑以下以串行/顺序方式读取文件数组的代码。readFiles返回一个promise,仅当依次读取所有文件后,promise才会解析。 var readFile = function(file) { ... // Returns a promise. }; var readFiles = function(files) { return new Promise((resolve, reject) => var readSequential = function(index) { if (index >= files.length) { resolve(); } else { readFile(files[index]).then(function() { readSequential(index + 1); }).catch(reject); } }; readSequential(0); // Start! }); }; 上面的代码可以工作,但是我不喜欢必须递归使事情顺序发生。有没有更简单的方法可以重写此代码,这样我就不必使用怪异的代码了readSequential函数了? …

5
jQuery Mobile:准备文档与页面事件
我正在使用jQuery Mobile,并且无法理解经典文档就绪和jQuery Mobile页面事件之间的区别。 真正的区别是什么? 为何要 <!-- language: lang-js --> $(document).ready() { }); 胜过 $(document).on('pageinit') { }); 从一页切换到另一页时,页面事件的顺序是什么? 如何将数据从一页发送到另一页,并且可以访问前一页的数据?


15
从选择框中删除项目
如何从选择框中删除项目或向其中添加项目?我正在运行jQuery,这应该使任务更轻松。下面是一个示例选择框。 <select name="selectBox" id="selectBox"> <option value="option1">option1</option> <option value="option2">option2</option> <option value="option3">option3</option> <option value="option4">option4</option> </select>

30
循环反向真的更快吗?
我已经听过好几次了。向后计数时,JavaScript循环真的更快吗?如果是这样,为什么?我已经看到了一些测试套件示例,这些示例显示了反向循环更快,但是我找不到关于原因的任何解释! 我假设这是因为循环不再需要在每次检查是否完成时都求值一个属性,而只需要检查最终的数值即可。 即 for (var i = count - 1; i >= 0; i--) { // count is only evaluated once and then the comparison is always on 0. }

5
用document.write()写入时,为什么要拆分<script>标记?
为什么某些网站(或为客户提供JavaScript代码的广告商)采用在呼叫内拆分&lt;script&gt;和/或&lt;/script&gt;标签的技术document.write()? 我注意到亚马逊也这样做,例如: &lt;script type='text/javascript'&gt; if (typeof window['jQuery'] == 'undefined') document.write('&lt;scr'+'ipt type="text/javascript" src="http://z-ecx.images-amazon.com/images/G/01/javascripts/lib/jquery/jquery-1.2.6.pack._V265113567_.js"&gt;&lt;/sc'+'ript&gt;'); &lt;/script&gt;
268 javascript  html 


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.