gpt4 book ai didi

php - PHP 中的 JavaScript

转载 作者:行者123 更新时间:2023-12-01 03:24:30 24 4
gpt4 key购买 nike

我正在尝试在 jquery 中执行以下操作

<?php

echo "<script>";
echo "$(document).ready(function(){";
echo "$('#mainbody-wrapper').removeClass('mainbody-wrapper')";
echo ";";
echo "$('#mainbody-wrapper').addClass('newStyle')";

echo ";";
echo "contentHeight=$('.content').css('height') + 20";
echo ";";

echo "alert(contentHeight)";
echo ";";
echo "$('#mainbody-wrapper').css('height',contentHeight)";
echo ";";
echo "$('#subcontent-wrapper').remove()";
echo ";";
echo "})";
echo "</script>";

?>

但是变量contentHeight输出300px20。我想做 javascript 添加,但它被串联起来。如何实现这一目标?

最佳答案

如果你只是想读取高度,jquery 有 height方法

echo "contentHeight=$('.content').height() + 20";

来自文档:

The difference between .css('height') and .height() is that the latter returns a unit-less pixel value (for example, 400) while the former returns a value with units intact (for example, 400px). The .height() method is recommended when an element's height needs to be used in a mathematical calculation.

关于php - PHP 中的 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6715191/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com