Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在jquery for css参数中不再使用css_Jquery_Css - Fatal编程技术网

如何在jquery for css参数中不再使用css

如何在jquery for css参数中不再使用css,jquery,css,Jquery,Css,这就是我们所做的css width: 200px; height: 100px; background-color: #f00; 当我们不想再使用css时,我们可以只添加一个斜杠或任何css不理解但其他css都可以使用的东西 widt/h: 200px; height: 100px; background-color: #f00; 但是我想在jquery中这样做,就像在jquery中的marginLef/t一样,它不再适用于所有其他参数 示例jquery <script> $(d

这就是我们所做的css

width: 200px;
height: 100px;
background-color: #f00;
当我们不想再使用css时,我们可以只添加一个斜杠或任何css不理解但其他css都可以使用的东西

widt/h: 200px;
height: 100px;
background-color: #f00;
但是我想在jquery中这样做,就像在jquery中的
marginLef/t
一样,它不再适用于所有其他参数

示例jquery

<script>
$(document).ready(function(){
  $("button").click(function(){
    $("h2").animate({backgroundColor: '#00f', width: '-=150px', marginLef/t: '50px'});
  });
});
</script>

$(文档).ready(函数(){
$(“按钮”)。单击(函数(){
$(“h2”).animate({背景颜色:'#00f',宽度:'-=150px',marginref/t:'50px'});
});
});

使用注释,而不是破坏代码。对于CSS:

/* width: 200px; this rule is obsolete for now */
height: 100px;
background-color: #f00;
在Javascript中:

alert('this line is executed');
// alert('this line is not');
/* removed following line in a multiline comment
alert('also not being executed');
*/
注释可确保不会将值作为一个整体进行解析,并且不会破坏解析器/编译器等其他功能


虽然CSS标准明确规定应忽略格式错误的规则,并且仍应用其他有效的规则,但在Javascript等编译器语言中,它只是破坏整个执行。

使用注释而不是破坏代码。对于CSS:

/* width: 200px; this rule is obsolete for now */
height: 100px;
background-color: #f00;
在Javascript中:

alert('this line is executed');
// alert('this line is not');
/* removed following line in a multiline comment
alert('also not being executed');
*/
注释可确保不会将值作为一个整体进行解析,并且不会破坏解析器/编译器等其他功能


虽然CSS标准明确规定应该忽略格式错误的规则,并且仍然应用其他有效的规则,但在Javascript这样的编译器语言中,它只是破坏了整个执行。

创建两个不同的类,一个有宽度,一个没有宽度,不是更容易吗。然后用jQuery使用addClass和removeClass或toggleClass更改元素的类。

创建两个不同的类,一个有宽度,另一个没有宽度,不是更容易吗。然后使用jQuery使用addClass和removeClass或toggleClass更改元素的类。

为什么不删除它?这将在下次使用。请显示您尝试过的jQuery代码。为什么不注释掉未使用的部分
/*注释是您的朋友*/
@C-Link,尝试设置“margin lef\t”(引号中)而不是marginLef\t为什么不删除它?这将在下次使用。请显示您尝试过的jquery代码。为什么不将未使用的部分注释掉
/*评论是你的朋友*/
@C-Link,尝试设置“margin lef\t”(引号中)而不是marginLef\t我知道我们的评论方式,但我提出了这个问题,以便下次jquery开发人员解决这个问题。我知道我们的评论方式,但我提出了这个问题,以便下次jquery开发人员解决这个问题。