我是javascript的新手,我有一個獲取文本框值並將其返回的函數,但我無法使用外部返回值的功能。我想讓函數返回一個字符串並將其顯示在網頁中。以下是代碼。如何從文本框中獲取字符串並在頁面中顯示javascript
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<!DOCTYPE html>
<html>
<head>
<title> Inventory test </title>
</head>
<body>
<script type="text/javascript">
function function1(){
var x = document.getElementById("text1").value;
if (x.length == ""){
alert ("input is empty");
}else{
alert (x + " " + "fine");
return x;
}
}
</script>
First name: <input type="text" id="text1" name="text1" autofocus>
<button onclick="function1()"> submit </button>
<p id="p1">p1</p>
</body>
</html>
感謝您的回覆,我希望該函數返回一個字符串,我想發送到數據庫服務器來查詢我不想將其設置爲另一個對象。 – smgopinath 2014-09-30 06:04:27