首页 > 解决方案 > 如何在另一个页面中创建表单提交链接并获取链接页面上提交的文本内容?

问题描述

我最近一直在尝试用 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>

标签: javascripthtml

解决方案


推荐阅读