首页 > 解决方案 > 如何激活隐藏输入的功能?

问题描述

我有一个简单的脚本,允许用户在输入中输入一个值。然后将这些值连接起来形成一个 URL,该 URL 将在 iframe 中打开页面。

它工作正常......但如果我想在第三个输入(完整 URL)上隐藏结果,并且只向用户显示他们输入的值,我无法触发第三个输入来显示 iframe 页面。

请看这段代码:

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


<input class="form-control form-control-sm mt-1 noenter" type="text" id="actpart1" value="116-2"/>

<input class="form-control form-control-sm mt-1 noenter" type="text" id="actpart2" value="116-261"/>
    
<button onClick="javascript: window.open('document.getElementById('acturl').value);">Go</button>


<input type="text" id="acturl" value=""/ hidden>


<iframe id="actframe" src="" loading="lazy" width="100%" height="735" frameborder="0" marginheight="0" marginwidth="0"></iframe>

<script>
$('#actpart1, #actpart2, #section10a').bind('keypress blur', function() {
    $('#acturl').val('https://sample.app/' + $('#actpart1').val() + '/' +
                            $('#actpart2').val() + '.pdf');
});
</script>

<script>
$('input#acturl').on('propertychange paste keyup',function(){
  var url = this.value;
  $('#actframe').attr('src', url);
});
$('input#acturl').keyup();
</script>

请看到有一个隐藏的输入,连接的 URL 所在的位置。我想要的是在通过单击Go按钮隐藏的同时激活它。

我现在真的很坚持。非常感谢您的帮助,谢谢!

标签: javascripthtmljquery

解决方案


您需要<input type="hidden" id="acturl" value="xxxx">为隐藏的输入字段(不是type="text")编写,并包含该值。


推荐阅读