javascript - 如何在另一个页面中创建表单提交链接并获取链接页面上提交的文本内容?
问题描述
我最近一直在尝试用 HTML 创建一个查询(提出问题)页面。我有一个使用 get 方法的表单,我知道这是跨页面发送数据并将其与 JavaScript 一起使用的一种方法。是否可以在链接页面内创建包含表单数据的链接?
// Get the contents of //
var inputBox = document.getElementById('QueryTitle');
// Use the onkeyup to get the values of user input //
inputBox.onkeyup = function(){
// MAKE NO BAD TAGS APPEAR IN QUESTIONS //
const goodTags = ['<b>' , '</b>' , '<i>' , '</i>' , '<br>' , '</br>']
var tag = inputBox.value.match(/<.+>/)
if (tag && !goodTags.includes(tag[0])) { inputBox.value = inputBox.value.replace(tag[0], '') };
document.getElementById('QueryTitleOutput').innerHTML = inputBox.value;
}
// Get the questions contents, normally in the textarea of the page //
var textarea = document.getElementById('QueryInput');
// Use the onkeyup to get the values of user input //
textarea.onkeyup = function(){
// MAKE NO BAD TAGS APPEAR IN QUESTIONS //
const goodTags = ['<b>' , '</b>' , '<i>' , '</i>' , '<br>' , '</br>']
var tag = textarea.value.match(/<.+>/)
if (tag && !goodTags.includes(tag[0])) { textarea.value = textarea.value.replace(tag[0], '') };
document.getElementById('QueryOutputFrame').innerHTML = textarea.value;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- This the form that uses the get method to show data in the URL -->
<form action="Get Text As A Link.html" method="get">
<input type="text" id="QueryTitle" name="QueryTitle" placeholder="Ask Something">
<br>
<br>
<!-- this is the main query textarea !-->
<textarea id="QueryInput" name="QueryInput" style="width: 780px; height: 200px;">
</textarea>
<!-- Widgets for the textarea !-->
<br>
<div id="QueryTitleOutput">
</div>
<br>
<br>
<div id="QueryOutputFrame" style="width: 90%; height: 10em;">
</div>
</center>
<br>
<br>
<br>
<br>
<br>
<center>
<input type="submit" id="final" value="Submit Question" class="unhidden" class="btn btn-submit" onclick="location.href = 'Get Text As A Link.html';" onSubmit="">
</center>
</form>
解决方案
推荐阅读
- php - 如何在 url 中定义没有 '?{name}=' 的 post 变量?
- python - 为什么即使使用双端队列而不是列表,我仍然会收到“由于超时错误而终止”?
- go - 加载具有关联的模型
- c++ - STM32L4 Rx中断:没有调试错误就无法工作
- java - 在控制器中抛出 ResponseStatusException 不返回正文
- mysql - 如何模拟链接服务器宕机?
- asp.net-core - 是否可以使用不同的发件人电子邮件和配置电子邮件从 ASP.Net Core 中的 MimeKit 发送电子邮件?
- javascript - 如何使用 JavaScript 制作一个给出 3 位数加法问题和个位数乘法问题的数学问题生成器?
- python - 列表的聚合列
- c# - 如何将 CsvHelper 模型属性归因于控制数字解析?