javascript - 如何激活隐藏输入的功能?
问题描述
我有一个简单的脚本,允许用户在输入中输入一个值。然后将这些值连接起来形成一个 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
按钮隐藏的同时激活它。
我现在真的很坚持。非常感谢您的帮助,谢谢!
解决方案
您需要<input type="hidden" id="acturl" value="xxxx">
为隐藏的输入字段(不是type="text"
)编写,并包含该值。
推荐阅读
- python - 在 Python 中将频率转换为音符
- python - 在 discord.py wait_for 上带有 check() 的 TypeError
- python - Anaconda worker 无法启动,因为:与 localhost 的连接在 0.2 秒后超时。在 2.0 秒内尝试连接 7 > 次
- c - c - 作为具有静态持续时间的对象的初始值设定项的指针
- android - Flutter:通过坐标从图像中提取矩形
- python - 来自命令行的python脚本的时间函数
- amazon-web-services - 如何在 AWS ECS 上访问任务的 apache 容器?
- ios - 当测试自动更新订阅沙盒帐户时,要求在应用启动时提供凭据。应用程序上线后也会发生这种情况吗?
- c - 指针如何在以下代码块中工作?
- node.js - 从节点服务器到mysql数据库的多个连接,如何修复