简体   繁体   English

填写前一个跨度的输入时显示下一个跨度

[英]display next span when filling in input of previous span

I have 2 input fields in each span.我在每个跨度中有 2 个输入字段。 when the first span of the row is filled with some date, the next span should be visible.当行的第一个跨度填充了某个日期时,下一个跨度应该是可见的。

<span name="datalist_2field" class="display_inline xyz">
    <input type="text" class="datalist_2row_left" name="inputfield_smpc" value=""></input>
    <input type="text" class="datalist_2row_right" name="inputfield_evmpd" value=""></input>
</span>
<?PHP
for ($i=1; $i<=10; $i++)
{
    ?>
    <span name="datalist_2field" class="display_none xyz">
        <input type="text" class="datalist_2row_left" name="inputfield_smpc" value=""></input>
        <input type="text" class="datalist_2row_right" name="inputfield_evmpd" value=""></input>
    </span>
    <?PHP
}
?>

jQuery: jQuery:

$('input[name="inputfield_smpc"]').keyup(function(){
     $(span.xyz).next().removeClass('display_none');
     $(span.xyz).next().addClass("display_inline");
});

Unfortunately it doesn't work.不幸的是,它不起作用。 What's wrong?怎么了? Thanks!谢谢!

I'd recommend the change() event instead of keyup().我建议使用 change() 事件而不是 keyup()。 The reason you shouldn't use keyup() is because if a user inputs a value using autofill, it will not fire keyup().不应该使用 keyup() 的原因是如果用户使用自动填充输入一个值,它不会触发 keyup()。 However, autofill does fire the change() event, and your verification script will run, and the input will be verified.但是,自动填充确实会触发 change() 事件,并且您的验证脚本将运行,并且输入将被验证。

As for why it isn't working, you have至于为什么它不起作用,你有

.removeClass('display_none')

but the item you're trying to select doesn't have a class name called 'display_none'但是您尝试选择的项目没有名为“display_none”的类名

if your trying to change the css without using another class you can use something like this如果您尝试在不使用其他类的情况下更改 css,您可以使用类似这样的东西

.css("display", "block");

display_none need to be added to second input instead of the span based on your requirement. display_none需要根据您的要求添加到第二个输入而不是跨度。

Code sample for your first span: HTML您的第一个跨度的代码示例:HTML

<span name="datalist_2field" class="display_inline xyz">
<input type="text" class="datalist_2row_left" name="inputfield_smpc" value=""></input>
<input type="text" class="datalist_2row_right display_none" name="inputfield_evmpd" value=""></input>
</span>

jQuery jQuery

 $('input[name="inputfield_smpc"]').keyup(function(){
   $(this).next().removeClass('display_none');
   $(this).next().addClass("display_inline");
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM