Javascript 在单个JS条件中应用多行jQuery
我有几行jQuery,我只想在它满足条件要求时应用它们。代码如下:Javascript 在单个JS条件中应用多行jQuery,javascript,jquery,css,Javascript,Jquery,Css,我有几行jQuery,我只想在它满足条件要求时应用它们。代码如下: <script> $(function() { //<![CDATA[ if (location.pathname == "/one-page-checkout.asp") $('#content_area').css("height", "1400px"); <!-- fix footer issue --> $('#v65-onepage-Shi
<script>
$(function() {
//<![CDATA[
if (location.pathname == "/one-page-checkout.asp")
$('#content_area').css("height", "1400px"); <!-- fix footer issue -->
$('#v65-onepage-ShippingCostDetails tr:nth-child(3)').css("display", "none");
//]]>
});
</script>
第一行$'content_area'.csheigh,1400px;,只在URL具有/one-page-checkout.asp时应用。但是第二行,$'v65-onepage-ShippingCostDetails tr:nth-child3'.cssdisplay,none;,在我的网站上普遍应用
我怎样才能使第二行,以及其后的任何一行,服从条件呢 您缺少if语句中的大括号:
if (location.pathname == "/one-page-checkout.asp") {
$('#content_area').css("height", "1400px"); <!-- fix footer issue -->
$('#v65-onepage-ShippingCostDetails tr:nth-child(3)').css("display", "none");
}
不使用大括号是完全有效的,但是如果这样做,那么如果语句为true,则只执行下面的一行。这可能会导致维护过程中出现错误。缩进只是为了可读性,它对代码的执行没有任何影响
您的代码按原样解释如下:
if (location.pathname == "/one-page-checkout.asp")
$('#content_area').css("height", "1400px"); <!-- fix footer issue -->
$('#v65-onepage-ShippingCostDetails tr:nth-child(3)').css("display", "none");
您缺少if语句中的大括号:
if (location.pathname == "/one-page-checkout.asp") {
$('#content_area').css("height", "1400px"); <!-- fix footer issue -->
$('#v65-onepage-ShippingCostDetails tr:nth-child(3)').css("display", "none");
}
不使用大括号是完全有效的,但是如果这样做,那么如果语句为true,则只执行下面的一行。这可能会导致维护过程中出现错误。缩进只是为了可读性,它对代码的执行没有任何影响
您的代码按原样解释如下:
if (location.pathname == "/one-page-checkout.asp")
$('#content_area').css("height", "1400px"); <!-- fix footer issue -->
$('#v65-onepage-ShippingCostDetails tr:nth-child(3)').css("display", "none");
哦。总是一些小事。谢谢你,噢。总是一些小事。谢谢你。