我根据其他StackOverflow问题/答案设置了一些Jquery.这个脚本的目的是它使整个div成为基于该div内的任何href标记的链接.
这工作正常,但我需要将其设置为_blank以在新选项卡中打开.我已经尝试了以下没有运气.
$(document).ready(function() {
$(".product-item").click(function() {
$(this).target = "_blank";
window.location = $(this).find("a").attr("href");
return false;
});
});
Run Code Online (Sandbox Code Playgroud)
编辑
感谢您的帮助,但这些答案都没有实际效果.如果任何人都可以粘贴实际工作的完整代码,而不是没有测试的小片段,如果它工作.谢谢.
编辑2
感谢kristinalim,提供完整的工作解决方案.
我一直在使用不同的方法从活动记录中获取特定字段,但是哪种方法更快且更受欢迎,它们之间有何不同?
User.all.collect(&:name)
User.all.pluck(:name)
User.all.select(:name)
User.all.map(&:name)
Run Code Online (Sandbox Code Playgroud)
提前感谢您的帮助。
我有一个Mongoose架构Employee.在此我想存储与办公室员工的字段(电话号码),只有当他/她可享有办公室,里面只有两个层次"高级"和"C级".
架构:
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
var EmployeeSchema = new Schema({
name: String,
designation: String,
level: {type: String, enum: ["intern", "junior", "mid-level", "senior", "c-level"], required: true},
phoneNo: {type: String, required: true},
officePhoneNo: {type: String, required: true} // how to require only if the level is senior or c-level?,
});
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助.
谢谢
有没有什么技巧可以在不使用任何函数和方法的情况下在javascript中将字符串转换为整数?
var s = "5"
console.log(typeof(s)) // out put is string
console.log(typeof(parseInt(s))) // i want out put which is number with out using parseInt() or other functions for optimizing code.Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激。提前致谢。
我是角度2的新人所以请帮助我.
我想实现angular 2和angular 4来从数据库中获取数据并在其上应用服务器端分页.
这个问题已经被问过很多次了,我经历了其中的大部分,但没有一个能帮助我找到解决方案。
我正在使用 for 循环生成几个条形图作为报告功能的一部分。
我正在使用带有 Express Handlebars 的 node.js。
我的页面看起来像:
<div class="row report-charts">
<div class="col-md-12">
{{#buildings}}
<div class="col-md-6">
<h4>{{Name}}</h4>
<canvas id="{{idBuildings}}" width="200" height="80"></canvas>
</div>
{{/buildings}}
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我的 js 代码如下所示:
$('.case-report-btn').click(function(){
$.ajax({
type: 'post',
url: '/reports/cases/filter',
data : {
StartDate : $('.start-ms-time-hidden').val(),
EndDate : $('.end-ms-time-hidden').val(),
ReportKey : $('.cases-filter-type').val()
},
dataType: 'json',
success: function(res) {
$('.report-charts').show();
for(key in res) {
var innerObj = res[key]; //gives the inner obj
var ctx = document.getElementById(key); //the idBuildings
var labels = [];
var data = …Run Code Online (Sandbox Code Playgroud) javascript ×2
jquery ×2
node.js ×2
activerecord ×1
angular ×1
chart.js ×1
mongoose ×1
pagination ×1
ruby ×1
server-side ×1