我有以下代码,这会创建我在文本字段中输入的文本字段的数量。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Dashboard | BlueWhale Admin</title>
<link rel="stylesheet" type="text/css" href="../css/reset.css" media="screen" />
<link rel="stylesheet" type="text/css" href="../css/text.css" media="screen" />
<link rel="stylesheet" type="text/css" href="../css/grid.css" media="screen" />
<link rel="stylesheet" type="text/css" href="../css/layout.css" media="screen" />
<link rel="stylesheet" type="text/css" href="../css/nav.css" media="screen" />
<script type="text/javascript">
//<![CDATA[
function BuildFormFields($amount)
{
var
$container = document.getElementById('FormFields'),
$item, $field, $i;
$container.innerHTML = '';
for ($i = 0; $i < $amount; $i++) {
$item = document.createElement('div');
$item.style.margin = '3px';
$field = document.createElement('span');
$field.innerHTML = '<hr>'+'News '+ ($i+1) + " ";
$field.style.marginRight = '10px';
$item.appendChild($field);
$field = document.createElement('input');
$field.name = 'Design[' + $i + ']';
$field.id = 'Design[' + $i + ']';
$field.type = 'text';
$field.className = 'error';
$field.style.width = '500px';
$item.appendChild($field);
$container.appendChild($item);
}
}
function saveNews()
{
var value=document.getElementById("noOfNews").value;
if(value==="")
{
alert("Please Enter Some Data");
}
else
{
var $no = parseInt(value),$i;
for($i=0;$i < $no; $i++ )
{
var value1=document.getElementById( 'Design[' + $i + ']' ).value;
if(value1==="")
{
alert("Please enter Data");
break;
}
}
if($no===$i)
{
alert("Data Saved !!!");
}
}
}
//]]>
</script>
</head>
<body>
Number Of News Item To be Displayed <input id="noOfNews" type="text" onkeyup="BuildFormFields(parseInt(this.value, 10));" />
<div id="FormFields" style="margin: 20px 0px;"></div>
<button class="btn btn-blue" onclick="saveNews()">Save</button>
</body>
</html>
我正在使用 jsf 2.0 并希望将输入的数据保存到数据库中,任何想法如何实现这一点。
谢谢, 阿比奈