Questions tagged «javascript»

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



6
获取元素的父div
这应该真的很简单,但是我遇到了麻烦。如何获得子元素的父div? 我的HTML: <div id="test"> <p id="myParagraph">Testing</p> </div> 我的JavaScript: var pDoc = document.getElementById("myParagraph"); var parentDiv = ?????????? 我本来以为document.parent还是parent.container会工作,但我不断收到not defined错误。请注意,pDoc已定义,但不是其中的某些变量。 有任何想法吗? 附言:如果可能的话,我宁愿避免使用jQuery。


23
打字稿-克隆对象
我有一个超类是父(Entity)对于很多子类(Customer,Product,ProductCategory...) 我正在寻找一个可以动态克隆在Typescript中包含不同子对象的对象的方法。 例如:Customer具有不同的Product人,具有ProductCategory var cust:Customer = new Customer (); cust.name = "someName"; cust.products.push(new Product(someId1)); cust.products.push(new Product(someId2)); 为了克隆整个对象树,我在其中创建了一个函数 Entity public clone():any { var cloneObj = new this.constructor(); for (var attribut in this) { if(typeof this[attribut] === "object"){ cloneObj[attribut] = this.clone(); } else { cloneObj[attribut] = this[attribut]; } } return cloneObj; } …

7
Vue v-on:click在组件上不起作用
我正在尝试在组件内部使用on click指令,但它似乎不起作用。当我单击该组件时,应该在控制台中单击“测试”,什么也没有发生。我在控制台中看不到任何错误,所以我不知道我在做什么错。 index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>vuetest</title> </head> <body> <div id="app"></div> <!-- built files will be auto injected --> </body> </html> 应用程序 <template> <div id="app"> <test v-on:click="testFunction"></test> </div> </template> <script> import Test from './components/Test' export default { name: 'app', methods: { testFunction: function (event) { console.log('test clicked') …

15
ng-repeat完成事件
我想用表调用一些针对div的jQuery函数。该表填充了ng-repeat。 当我打电话时 $(document).ready() 我没有结果 也 $scope.$on('$viewContentLoaded', myFunc); 没有帮助。 ng-repeat填充完成后,有什么方法可以执行功能?我已经阅读了有关使用custom的建议directive,但是我不知道如何在ng-repeat和div中使用它。

14
使用jQuery的填充或边距值(以像素为单位)为整数
jQuery具有height()和width()函数,这些函数以整数形式返回像素的高度或宽度。 如何使用jQuery 以像素为单位并以整数形式获取元素的填充或边距值? 我的第一个想法是执行以下操作: var padding = parseInt(jQuery("myId").css("padding-top")); 但是,例如,如果在ems中给出了填充,我如何获得以像素为单位的值? 通过查看Chris Pebble建议的JSizes插件,我意识到我自己的版本是正确的:)。jQuery始终返回以像素为单位的值,因此只需将其解析为整数即可。 感谢克里斯·佩布尔(Chris Pebble)和伊恩·罗宾逊(Ian Robinson)
207 javascript  jquery  css 

6
jQuery的.bind()与.on()
我找到了两篇有关此新功能的精彩文章.on():jquery4u.com,elijahmanor.com。 有什么方法.bind()比它还好用.on()吗? 例如,我有一个示例代码,如下所示: $("#container").click( function( e ) {} ) 您可能注意到,选择器只检索了一项,在我的情况下,加载页面时该<div>名称#container已经存在;没有动态添加。重要的是要提到我使用的是最新版本的jQuery:1.7.2。 对于该示例,即使我不使用该功能提供的其他功能,也.on()应使用该示例?.bind().on()



18
jQuery的禁用表单提交输入
我的页面中似乎包含以下javascript,但似乎无法正常运行。 $('form').bind("keypress", function(e) { if (e.keyCode == 13) { e.preventDefault(); return false; } }); 我想在输入时禁用提交表单,或者更好的是,将其称为ajax表单提交。两种解决方案都可以接受,但是我上面包含的代码不会阻止表单的提交。



3
如何在mongodb中的对象数组中搜索
假设mongodb文档(表)“用户”为 { _id: 1, name: { first: 'John', last: 'Backus' }, birth: new Date('Dec 03, 1924'), death: new Date('Mar 17, 2007'), contribs: [ 'Fortran', 'ALGOL', 'Backus-Naur Form', 'FP' ], awards: [ { award: 'National Medal', year: 1975, by: 'NSF' }, { award: 'Turing Award', year: 1977, by: 'ACM' } ] …

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.