php - 将 iframe 文本传递给 laravel 控制器
问题描述
我遇到了问题...我的 iframe 基本上是一个输入框(下图),我想从用户那里获取输入到我的控制器我可以接受它传递文本的 html,这就是我期待,因为它不是一个普通的文本框,我不能只将它传递给 laravel,因为它运行 java 代码。有什么建议吗?
我的页面:
@extends('layouts.app')
@section('content')
<div class="content">
<div class="d-flex justify-content-center mt-sm-3">
<h3>Insert text</h3>
</div>
<div class="d-flex justify-content-center mt-xl-1">
<form method="POST" action="{{ route('test.create') }}">
@csrf
<iframe src="http://localhost:8080/test" width="560" height="650"></iframe>
<button type="submit" class="btn btn-outline-success w-100 mb-3">
Done
</button>
</form>
</div>
</div>
@endsection
图片(仅限 iframe 和按钮):
解决方案
我制作了这段代码,它在我身上运行良好。看看:
ex1.html:
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<form>
<input type="text" id="sachin"/>
</form>
</body>
</html>
ex.html:
<body>
<iframe src="ex1.html" id="iframeId" style="height:380px;width:100%"></iframe>
<script>
$(function(){
var iframe = document.getElementById("iframeId");
$(iframe).on('load',function(){
var innerDoc = (iframe.contentDocument)
? iframe.contentDocument
: iframe.contentWindow.document;
var input= $(innerDoc).find('#sachin');
$(input).on('keyup', function(){
//do anything with the value
console.log($(this).val());
});
});
});
</script>
</body>
希望这可以帮助。
推荐阅读
- java - SpringBoot:健康端点中缺少领事健康指标
- docker - Jenkins - 测试与远程私有 Docker 注册表的连接时出现 404
- cluster-computing - Ejabberd Clustor 文件上传不适用于一个节点到第二个节点
- android - 在全屏对话框顶部显示片段(alertDialog)
- python - 使用虚拟主机执行 python 脚本的 Apache
- swift - Swift:无法分配给属性:“reuseIdentifier”是一个只能获取的属性
- html - 尽管使用 displayWith 属性,但材料自动完成输入显示显示 [Object object]
- c++ - 将属性传递给基类的机制
- c# - 从 C# 中的动态 JSON 获取属性名称,然后在 foreach 循环中使用这些属性
- python - 块的 Python 类型提示