jQuery将div的高度设置为另一个的“动态高度”(jQuery set height of a div to the 'dynamic height' of another)
我有两个div。
<div class="col-1"><p>Content</p></div> <div class="col-2"><img src="" alt="" /></div>
每个人都有他们尊重的内容。
我正在设置col-2的高度与col-1的高度完全一致。
我尝试使用jQuery:
$(document).ready(function() { var divHeight = $('.col1').height(); $('.col2').css('min-height', divHeight+'px'); });
问题是col-1没有设置高度。 它的内容在增长时会有一个动态的高度。 因此,上面的代码不适用于它。
有没有什么办法可以将col-2的最小高度设置为与使用jQuery的col 1的动态高度相等?
I have two divs.
<div class="col-1"><p>Content</p></div> <div class="col-2"><img src="" alt="" /></div>
With their respected content inside each one.
I am trying to set the height of col-2 to be exactly as that of col-1.
I tried this using jQuery:
$(document).ready(function() { var divHeight = $('.col1').height(); $('.col2').css('min-height', divHeight+'px'); });
The problem is that col-1 does not have a height set on it. It has a dynamic height which grows when its content grows. Therefore the above code does not work for it.
Is there any way I can set the min height of col-2 to be equal to the dynamic height of col 1 using jQuery?
原文:https://stackoverflow.com/questions/32109683
最满意答案
一个简单的方法是检查
Integer.toHexString()
输出多少个数字,如果需要,可以向每个字节添加一个前导零。 这样的事情public static String toHexString(byte[] bytes) { StringBuilder hexString = new StringBuilder(); for (int i = 0; i < bytes.length; i++) { String hex = Integer.toHexString(0xFF & bytes[i]); if (hex.length() == 1) { hexString.append('0'); } hexString.append(hex); } return hexString.toString(); }
A simple approach would be to check how many digits are output by
Integer.toHexString()
and add a leading zero to each byte if needed. Something like this:public static String toHexString(byte[] bytes) { StringBuilder hexString = new StringBuilder(); for (int i = 0; i < bytes.length; i++) { String hex = Integer.toHexString(0xFF & bytes[i]); if (hex.length() == 1) { hexString.append('0'); } hexString.append(hex); } return hexString.toString(); }
相关问答
更多-
字节数组到十六进制字符串(Byte Array to Hex String)[2023-12-26]
使用str.format : >>> array_alpha = [ 133, 53, 234, 241 ] >>> print ''.join('{:02x}'.format(x) for x in array_alpha) 8535eaf1 或使用format >>> print ''.join(format(x, '02x') for x in array_alpha) 8535eaf1 注意:在格式声明中, 02表示如果需要,它将填充最多2个前导0 。 这是很重要的,因为[0x1, 0x1, 0 ... -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
这是一个很好的LINQ示例。 public static byte[] StringToByteArray(string hex) { return Enumerable.Range(0, hex.Length) .Where(x => x % 2 == 0) .Select(x => Convert.ToByte(hex.Substring(x, 2), 16)) .ToA ...
-
使用Java将十六进制转储的字符串表示转换为字节数组?(Convert a string representation of a hex dump to a byte array using Java?)[2022-12-09]
这是一个解决方案,我认为比任何发布到目前为止更好: public static byte[] hexStringToByteArray(String s) { int len = s.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) ... -
一个简单的方法是检查Integer.toHexString()输出多少个数字,如果需要,可以向每个字节添加一个前导零。 这样的事情 public static String toHexString(byte[] bytes) { StringBuilder hexString = new StringBuilder(); for (int i = 0; i < bytes.length; i++) { String hex = Integer.toHexString(0xF ...
-
从这里的讨论,特别是这个答案,这是我目前使用的功能: private final static char[] hexArray = "0123456789ABCDEF".toCharArray(); public static String bytesToHex(byte[] bytes) { char[] hexChars = new char[bytes.length * 2]; for ( int j = 0; j < bytes.length; j++ ) { int ...
-
string hexIpAddress = "0A010248"; // 10.1.2.72 => "0A010248" byte[] bytes = new byte[hexIpAddress.Length / 2]; for (int i = 0; i < hexIpAddress.Length; i += 2) bytes[i/2] = Convert.ToByte(hexIpAddress.Substring(i, 2), 16); 这导致了这个数组: bytes = {0x0A, 0x ...
-
试试if(byteArray[13] == (byte)0xec) Try if(byteArray[13] == (byte)0xec)
-
Java通用转换字节数组到字符串(非十六进制,十进制)(Java generic convert byte array to string (Non hex, decimal))[2023-08-05]
看起来你正在寻找Base64编码。 这使用64个不同的字符来编码一个值:大写和小写字母(已经是52个字符),数字(10个以上,包括'0'),以及'+'和'/'符号(或' - ')和url-safe变体中的'_')。 如果你使用的是Java 8,那就是Base64类: String str = Base64.Encoder.encodeToString(data); 否则,Apache Commons也有一个Base64类: String str = Base64.encodeBase64String(da ... -
尝试 byte[] getBytes(String s) { byte[] a = new byte[s.length() / 2]; for (int i = 0; i < a.length; i++) { a[i] = Byte.parseByte(s.substring(i * 2, i * 2 + 2), 16); } return a; } try byte[] getBytes(String s) { byte[] a = new byt ...