Tag: JavaScript

使用jQuery或纯JS获得多选框的价值

在下面显示的代码中,如何使用jQuery或纯JavaScript获取函数val()中多选框的值? <script> function val() { //Get values of mutliselect drop down box } $(document).ready(function () { var flag = 0; $('#emp').change(function () { var sub = $("OPTION:selected", this).val() if (flag == 1) $('#new_row').remove(); $('#topics').val(''); var html = '<tr id="new_row" class="new_row"><td>Topics:</td><td> <select id="topic_l" name="topic_l" class="topic_l" multiple="multiple">'; var idarr = new Array(); var valarr = new Array(); […]

从MongoDB ID获取时间戳

我如何从MongoDB ID获取时间戳?

同时使用jQuery timeago或者momentjs和AngularJS

我想用timeago插件使date看起来更好。 问题是这些date是通过dynamic从REST的AngularJS获取。 所以,当我将这个jQuery插件附加到我的页面时,它不会处理它。 那么,如何做得更好呢? 如果可能的话,我会很乐意运行没有jQuery。

如何使用JavaScript和CSS淡入和淡出

我想让HTML div标签淡入淡出。 我有一些淡出的代码,但是当我淡入时,div的不透明度保持在0.1,不增加。 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <title>Fade to Black</title> <script type="text/javascript"> //<![CDATA[ function slidePanel(elementToSlide, slideSource) { var element = document.getElementById(elementToSlide); if(element.up == null || element.up == false) { setTimeout("fadeOut(\"" + elementToSlide + "\")", 100); element.up = true; slideSource.innerHTML = "Bring it down"; } else { setTimeout("fadeIn(\"" […]

得到这个最合适的方法:$($(“。answer”))

假设我想获得类“.answer”中所有元素中的第一个元素, $($(".answer")[0]) 我可以做到以上,但优雅和速度之间的最佳平衡是什么? *改变了这个问题,以反映当前的讨论

jquery / JS阻止浏览器中的右键单击菜单

我有我的div与右键单击popup式菜单: // Attatch right click event to folder for extra options $('#fBox' + folderID).mousedown(function(event) { if (event.which == 3) { // Set ID currRClickFolder = folderID; // Calculate position to show popup menu var height = $('#folderRClickMenu').height(); var width = $('#folderRClickMenu').width(); leftVal = event.pageX – (width / 2) + "px"; topVal = event.pageY – (height) […]

在jquery中切换大小写

我正在写正确的开关盒吗? var cnt = $("#div1 p").length; alert(cnt); switch (cnt) { case (cnt >= 10 && cnt <= 20): alert('10'); break; case (cnt >= 21 && cnt <= 30): alert('21'); break; case (cnt >= 31 && cnt <= 40): alert('31'); break; default: alert('>41'); } 出于某种原因,条件匹配时不会发生警报!

如何将数组中的所有元素转换为JavaScript中的整数?

经过一些操作,我得到一个数组。 我需要将所有数组的值转换为整数。 我的示例代码 var result_string='a,b,c,d|1,2,3,4'; result=result_string.split("|"); alpha=result[0]; count=result[1]; //alert(alpha); //alert(count); count_array=count.split(","); count_array现在包含1,2,3,4但我需要这些值是整数。 我用过parseInt(count_array); ,但是失败了。 JS将这个数组中的每个值视为string。

NPM不再工作

所以我没有注意并且运行这个命令, npm install npm install jasmine-node -g 这导致了这一点 – npm http GET https://registry.npmjs.org/install npm http GET https://registry.npmjs.org/jasmine-node npm http GET https://registry.npmjs.org/npm npm http 200 https://registry.npmjs.org/install npm http GET https://registry.npmjs.org/install/-/install-0.1.7.tgz npm http 200 https://registry.npmjs.org/install/-/install-0.1.7.tgz npm http 200 https://registry.npmjs.org/jasmine-node npm http GET https://registry.npmjs.org/jasmine-node/-/jasmine-node-1.4.0.tgz npm http 200 https://registry.npmjs.org/jasmine-node/-/jasmine-node-1.4.0.tgz npm http 200 https://registry.npmjs.org/npm npm http GET https://registry.npmjs.org/npm/-/npm-1.2.15.tgz npm http […]

为什么gulp-useref在replace部分似乎不能使用注释?

我正在尝试构build一个gulppipe道 – 我想在我的index.html (这个工作正常)中注入一些CSS,然后从源index.html获取所有其他的链接,并将其replace为输出的版本。 我注意到, 如果要replace的模板部分包含HTML注释 ,请参阅useref调用来修改输出(有关注释 ,请参阅下面的示例)。 用代码演示最简单: index.html (源文件) <!– build:css styles/app.css–> <!–COMMENT–> <link rel="stylesheet" href="/.tmp/styles.css"> <!– endbuild –> gulpfile.js任务 gulp.task('optimizeReplace', function () { var assets = $.useref.assets({ searchPath: './' }); return gulp .src('./src/client/index.html') .pipe(assets) .pipe(assets.restore()) .pipe($.useref()) //THIS IS THE PROBLEM LINE; IF INJECT IS NOT RUN FIRST IT IS MANGLED .pipe(gulp.dest('./wwwroot/')); }); […]