gpt4 book ai didi

jquery - 获取当前视口(viewport)上元素的正确值

转载 作者:太空宇宙 更新时间:2023-11-04 00:37:06 24 4
gpt4 key购买 nike

这是我的代码。

<!-- desktop -->
<div class="section hidden-xs">
<input name="code" type="text" value="123">
</div>
...
<!-- mobile -->
<div class="section">
<input name="code" type="text" value="456">
</div>

$('input[name="code"]').val() 总是返回 123 即使我在桌面和移动设备上也是如此。

有没有办法在每台设备上获取正确的值?

最佳答案

你应该使用`:visible获取可见值。

$('input[name="code"]:visible').val()

现在您只是获取页面上第一个的值,即使它是不可见的,因为这就是 jQuery 中 getter 的工作方式。参见 Get the sum of the outerHeight of all elements of the same class

关于jquery - 获取当前视口(viewport)上元素的正确值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59165332/

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