[英]How Can I set variable width with !importanat using JavaScript/jQuery
Ia have a div named "#idDayNrCell".我有一个名为“#idDayNrCell”的 div。 I want to get its width then do some calculations and apply it to another div called ".event".
我想得到它的宽度然后做一些计算并将它应用到另一个名为“.event”的div。 I am using bootstrap so i need to apply !important aswell.
我正在使用引导程序,所以我还需要应用 !important。 I am new to javascript/jquery.
我是 javascript/jquery 的新手。
I tried something like this.我试过这样的事情。 But it didn't wotk
但它没有起作用
$(document).ready(function(){
var cellWDTstr = ($("#idDayNrCell").css("width")); //get width
var cellWDT = cellWDTstr.substr(0,cellWDTstr.length-2); //remove the "px" part
console.log(cellWDT);
var GunSayisi=2; //how long is the event (2 for example)
// after tihs things get complicated for me
// if the even is minimum 2 days i need a different width. calculated below
var wdtEnAz2 = ((cellWDT-30)*GunSayisi + 30*(GunSayisi-1)).toString();
console.log(wdtEnAz2);
var setWdt = GunSayisi>1 ? wdtEnAz2 : calWdt;
//after here it is expoerimental code which I am failed
console.log(setWdt);
setWdt+= 'px';
console.log(setWdt);
$(".event").style.setPsetProperty('width',setWdt,'important');
});
this is the html这是 html
Using ES6,使用 ES6,
var width = "100px";
$(".event").attr('style', `width: ${width} !important`);
像这样添加:
$('.event').attr('style', 'width: '+ setWdt +' !important');
You can use css property from jquery, please find below code snippet :您可以使用 jquery 的 css 属性,请查看以下代码片段:
$(".event").css( "width", function(
setWtd ) {
return setWtd + '!Important';
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.