【问题标题】:Make input element invisible使输入元素不可见
【发布时间】:2015-09-25 01:11:41
【问题描述】:

您好,我尝试获取特定列表项的变量。我想意识到,在这种情况下,使用不可见的输入元素在那里设置值,并尝试在简单的 php if 条件下获取变量的值。那不可见,这应该意味着用户不会看到输入元素,我试图用 jquery 1.8.2 来做,但它不会工作。我应该改变什么?欢迎对如何在 php 中获取列表项的值提出改进建议。

$(document).ready(function () {
    $("#timex").change(function () {
        if ($(this).val() == "0") {
            $("#timex").hide();
        }

    });
});

我在 foreach 循环中的 html 代码:

<a href="#popupcomment" data-rel="popup" data-position-to="window" data-transition="pop">comment</a> 
<div data-role="popup" id="popupcomment" data-theme="a" class="ui-corner-all">
    <form data-ajax="false" name="login-form" class="login-form" action="./range.php" method="post" style="padding:20px 40px;">
        <div class="content">
            <input name="timex" id="timex" value="<?php echo $row['time']; ?>" type="text" />
            <textarea rows="5" name="text" id="text" class="foo"></textarea>
        </div>
        <div class="footer">
            <input type="submit" name="save" value="comment" class="button" data-theme="a" />
        </div>
    </form>
</div>

【问题讨论】:

  • 我猜你要找的是 input type="hidden"

标签: javascript php jquery html mobile


【解决方案1】:

运行 sn-p,并将值更改为 0(然后按 Enter)。

注意:更改type 属性仅适用于较新版本的jQuery。 .hide() 适用于 jQuery 1.8.2

$(document).ready(function () {
    $("#timex").change(function () {
        if ($(this).val() == "0") {
            $(this).attr('type', 'hidden');
        }
    });
  
    $("#timey").change(function () {
        if ($(this).val() == "0") {
            $(this).hide();
        }
    });
});
<input name="timex" id="timex" value="5" type="text" />
<input name="timey" id="timey" value="8" type="text" />

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-18
    • 1970-01-01
    • 1970-01-01
    • 2021-03-09
    • 2017-04-06
    • 1970-01-01
    • 2023-03-16
    相关资源
    最近更新 更多