<table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_form">
<tr>
<form name="addnews" action="addnews.php" method="GET">
<th width="90%" align="right">
<div align="right">
<select name="newtypeid" id="newtypeid">
<option value="0">--所有栏目--</option>
<?php
$sql = "select * from newtype";
$conn = mysql_connect("localhost","root","123456");
$st = mysql_select_db("install",$conn);
mysql_query("set names gbk");
$rs = mysql_query($sql);;
while ($row = mysql_fetch_array($rs, MYSQL_BOTH))
{
echo "<option value=".$row[typeid].">".$row["typetitle"]."</option>"; }
mysql_free_result($rs);
mysql_close($conn);
?>
</select>
</div></th>
<th width="10%" align="right"><input name="addnews" type="submit" value="添加新闻"></th>
</form>
</tr>
</table>
如果我使用默认的如:--所有栏目-- 那么,我点击添加新闻的话,则提示“请选择要添加的栏目”,如果我选择企业访谈的话,则可以进入下一步
<tr>
<form name="addnews" action="addnews.php" method="GET">
<th width="90%" align="right">
<div align="right">
<select name="newtypeid" id="newtypeid">
<option value="0">--所有栏目--</option>
<?php
$sql = "select * from newtype";
$conn = mysql_connect("localhost","root","123456");
$st = mysql_select_db("install",$conn);
mysql_query("set names gbk");
$rs = mysql_query($sql);;
while ($row = mysql_fetch_array($rs, MYSQL_BOTH))
{
echo "<option value=".$row[typeid].">".$row["typetitle"]."</option>"; }
mysql_free_result($rs);
mysql_close($conn);
?>
</select>
</div></th>
<th width="10%" align="right"><input name="addnews" type="submit" value="添加新闻"></th>
</form>
</tr>
</table>
如果我使用默认的如:--所有栏目-- 那么,我点击添加新闻的话,则提示“请选择要添加的栏目”,如果我选择企业访谈的话,则可以进入下一步
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_form">
<tr>
<form name="addnews" action="addnews.php" method="GET">
<th width="90%" align="right">
<div align="right">
<select name="newtypeid" id="newtypeid">
<option value="0">--所有栏目--</option>
<?php
$sql = "select * from newtype";
$conn = mysql_connect("localhost","root","123456");$st = mysql_select_db("install",$conn);
mysql_query("set names gbk");
$rs = mysql_query($sql);;
while ($row = mysql_fetch_array($rs, MYSQL_BOTH))
{echo "<option value=".$row[typeid].">".$row["typetitle"]."</option>";}
mysql_free_result($rs);
mysql_close($conn);?>
</select>
</div></th>
<th width="10%" align="right"><input name="addnews" type="submit" value="添加新闻"></th>
</form>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_form">
<tr>
<form name="addnews" action="addnews.php" method="GET">
<th width="90%" align="right">
<div align="right">
<select name="newtypeid" id="newtypeid">
<option value="0">--所有栏目--</option>
<?php
$sql = "select * from newtype";
$conn = mysql_connect("localhost","root","123456");$st = mysql_select_db("install",$conn);
mysql_query("set names gbk");
$rs = mysql_query($sql);;
while ($row = mysql_fetch_array($rs, MYSQL_BOTH))
{echo "<option value=".$row[typeid].">".$row["typetitle"]."</option>";}
mysql_free_result($rs);
mysql_close($conn);?>
</select>
</div></th>
<th width="10%" align="right"><input name="addnews" type="submit" value="添加新闻"></th>
</form>
</tr>
</table>
function aaa(){
if(document.getElementById('newtypeid').value=='0'){
alert('请选择要添加的栏目'); document.getElementById('newtypeid').focus(); return false
}
}
</script>
<form name="addnews" action="addnews.php" method="GET" onsubmit='return aaa()'>
<!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">
<head>
<title> new document </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style></style>
<script src="jquery-1.3.2.js"></script>
<script>
$(function(){
$("#input").click(function(){
var value = $("#newtypeid option:selected").text();
if(value =="--所有栏目--"){
alert("请选择要添加的栏目");
return;//停止执行
}
if(value =="企业访谈"){
alert("写上你自己的操作");
}
});
});
</script>
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_form">
<tr>
<form name="addnews" action="addnews.php" method="GET">
<th width="90%" align="right">
<div align="right">
<select name="newtypeid" id="newtypeid">
<option value="0">--所有栏目--</option>
<option>企业访谈</option>
<option>企业访谈</option>
<option>企业访谈</option>
<?php
$sql = "select * from newtype";
$conn = mysql_connect("localhost","root","123456");$st = mysql_select_db("install",$conn);
mysql_query("set names gbk");
$rs = mysql_query($sql);;
while ($row = mysql_fetch_array($rs, MYSQL_BOTH))
{echo "<option value=".$row[typeid].">".$row["typetitle"]."</option>";}
mysql_free_result($rs);
mysql_close($conn);?>
</select>
</div></th>
<th width="10%" align="right"><input name="addnews" type="submit" id="input" value="添加新闻"></th>
</form>
</tr>
</table>
</body>
</html>