Questions tagged «javascript»

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

14
资源因MIME类型不匹配而被阻止(X-Content-Type-Options:nosniff)
我正在使用JavaScript和HTML开发网页,当我从HTML页面收到以下错误列表时,一切工作正常: The resource from “https://raw.githubusercontent.com/dataarts/dat.gui/master/build/dat.gui.min.js” was blocked due to MIME type mismatch (X-Content-Type-Options: nosniff). The resource from “https://raw.githubusercontent.com/mrdoob/three.js/dev/build/three.js” was blocked due to MIME type mismatch (X-Content-Type-Options: nosniff). The resource from “https://raw.githubusercontent.com/mrdoob/three.js/master/examples/js/renderers/CanvasRenderer.js” was blocked due to MIME type mismatch (X-Content-Type-Options: nosniff). The resource from “https://raw.githubusercontent.com/mrdoob/three.js/master/examples/js/renderers/Projector.js” was blocked due to MIME type …
90 javascript  mime 

10
将事件附加到javascript中的动态元素
我正在尝试将html数据动态地插入到动态创建的列表中,但是当我尝试为动态创建的按钮附加onclick事件时,则不会触发该事件。解决方案将不胜感激。 JavaScript代码: document.addEventListener('DOMContentLoaded', function () { document.getElementById('btnSubmit').addEventListener('click', function () { var name = document.getElementById('txtName').value; var mobile = document.getElementById('txtMobile').value; var html = '<ul>'; for (i = 0; i < 5; i++) { html = html + '<li>' + name + i + '</li>'; } html = html + '</ul>'; html = …
90 javascript 

14
猫鼬打字稿方式...?
试图在Typescript中实现Mongoose模型。对Google的调查只揭示了一种混合方法(结合JS和TS)。如果没有JS,如何以我比较幼稚的方式实现User类呢? 希望能够不带行李的IUserModel。 import {IUser} from './user.ts'; import {Document, Schema, Model} from 'mongoose'; // mixing in a couple of interfaces interface IUserDocument extends IUser, Document {} // mongoose, why oh why '[String]' // TODO: investigate out why mongoose needs its own data types let userSchema: Schema = new Schema({ userName : …

12
TypeError:$(…).DataTable不是函数
我正在尝试通过此链接为我的项目使用jQuery的Datatable JS 。 我从同一来源下载了完整的库。软件包中给出的所有示例似乎都可以正常工作,但是当我尝试将其合并到我WebForms的CSS,JS中时,它们根本无法工作。 这是我所做的: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <link href="css/jquery.dataTables.css" rel="stylesheet" type="text/css" /> </head> <body> <form id="form1" runat="server"> <div> <table id="myTable" class="display" cellspacing="0" width="100%"> <thead> <tr> <th>Name</th> <th>Position</th> <th>Office</th> <th>Age</th> <th>Start date</th> <th>Salary</th> </tr> </thead> <tfoot> <tr> <th>Name</th> <th>Position</th> <th>Office</th> <th>Age</th> <th>Start date</th> <th>Salary</th> </tr> </tfoot> <tbody> <!-- …

12
Vue.js动态图像无法正常工作
我有一种情况,在Vue.js使用webpack网络应用程序时,我需要显示动态图像。我想显示img图像文件名存储在变量中的位置。该变量是一个computed属性,它返回一个Vuex存储变量,该变量在上异步填充beforeMount。 <div class="col-lg-2" v-for="pic in pics"> <img v-bind:src="'../assets/' + pic + '.png'" v-bind:alt="pic"> </div> 但是,当我刚做的时候它完美地工作: <img src="../assets/dog.png" alt="dog"> 我的情况与此小提琴类似,但是在这里它适用于img URL,但是在我的具有实际文件路径的情况下,它不起作用。 正确的方法是什么?

3
使用原型迭代JavaScript中对象的每个属性?
有没有一种方法可以使用Prototype JavaScript框架遍历对象的每个属性? 情况如下:我正在JSON中收到AJAX响应,看起来像这样: {foo: 1, bar: 2, barobj: {75: true, 76: false, 85: true}} 如果我将json响应评估为变量response,则希望能够遍历response.barobj对象中的每个属性,以查看哪些索引为真,哪些索引为假。 原型具有两者Object.keys(),Object.values()但奇怪的是似乎没有简单的Object.each()功能!我可以获取Object.keys()和Object.values()的结果,并在遍历一个对象时交叉引用另一个对象,但这是一个hack,我相信有正确的方法可以做到这一点!

9
对象转储JavaScript
是否有第三方插件/应用程序或某种方法可以在脚本调试器中为JavaScript对象执行对象映射转储? 这是一种情况...我有两次被调用的方法,每次都不同。我不确定有什么不同,但是有什么不同。因此,如果我可以将window(或至少window.document)的所有属性转储到文本编辑器中,则可以使用简单的文件diff比较两个调用之间的状态。有什么想法吗?
89 javascript 

15
使用Backbone.js反向排序
使用Backbone.js,我可以使用比较器功能来设置集合。很好地对模型进行了排序,但是我想颠倒顺序。 如何对模型进行降序排序而不是升序排序?

6
javascript jquery单选按钮单击
我有2个单选按钮和jquery正在运行。 <input type="radio" name="lom" value="1" checked> first <input type="radio" name="lom" value="2"> second 现在,使用按钮,我可以将onClick设置为运行功能。单击单选按钮时,使单选按钮运行功能的方式是什么?

6
删除除一个以外的所有类
好吧,我知道,通过一些jQuery动作,我们可以为特定的div添加很多类: <div class="cleanstate"></div> 假设通过点击和其他操作,div获得了很多类 <div class="cleanstate bgred paddingleft allcaptions ..."></div> 那么,如何删除除一个类之外的所有类?我提出的唯一想法是: $('#container div.cleanstate').removeClass().addClass('cleanstate'); 虽然removeClass()杀死所有类,但div搞砸了,但是在此之后添加addClass('cleanstate')它又恢复了正常。另一种解决方案是将ID属性与基本CSS属性放在一起,这样它们就不会被删除,这也可以提高性能,但是我只想知道另一种解决方案,以摆脱“ .cleanstate”之外的所有问题。 我之所以这样问是因为,在实际的脚本中,div遭受了类的各种更改。


8
jQuery按值选择选项元素
我有一个由span元素包裹的select元素。我不允许使用选择ID,但可以使用跨度ID。我正在尝试编写一个javascript / jquery函数,其中输入为数字i,这是select选项的值之一。该功能会将相关选项变为选中状态。 <span id="span_id"> <select id="h273yrjdfhgsfyiruwyiywer" multiple="multiple"> <option value="1">cleaning</option> <option value="2">food-2</option> <option value="3">toilet</option> <option value="4">baby</option> <option value="6">knick-knacks</option> <option value="9">junk-2</option> <option value="10">cosmetics</option> </select> </span> 我写了一些东西(这不能完全起作用,这就是为什么我要发布这个问题): function select_option(i) { options = $('#span_id').children('select').children('option'); //alert(options.length); //7 //alert(options[0]); //[object HTMLOptionElement] //alert(options[0].val()); //not a jquery element //alert(options[0].value); //1 //the following does not seem to work …


6
使用AngularJS中的UI-Router将状态重定向到默认子状态
我正在创建一个基于标签的页面,其中显示了一些数据。我在AngularJs中使用UI-Router来注册状态。 我的目标是在页面加载时打开一个默认选项卡。每个选项卡都有子选项卡,我想在更改选项卡时打开默认的子选项卡。 我正在使用onEnter函数进行测试,并且正在使用内部,$state.go('mainstate.substate');但是由于循环效应问题(在state.go上对其子状态调用它的父状态,依此类推,然后变成循环),它似乎无法正常工作。 $stateProvider .state('main', { url: '/main', templateUrl: 'main.html', onEnter: function($state) { $state.go('main.street'); } }) .state('main.street', { url: '/street', templateUrl: 'submenu.html', params: {tabName: 'street'} }) 在这里,我创建了一个plunker演示。 目前,一切正常,除了我没有打开默认选项卡,而这正是我所需要的。 感谢您的建议,意见和想法。


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.