程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> php-JS判斷文本框是否是空的問題,為什麼我的代碼不能判斷,就指點

php-JS判斷文本框是否是空的問題,為什麼我的代碼不能判斷,就指點

編輯:編程綜合問答
JS判斷文本框是否是空的問題,為什麼我的代碼不能判斷,就指點

<?php
$conn = mysql_connect ( 'localhost', 'root', 'admin' ) or die ( 'could not connect: ' . mysql_error () );
mysql_select_db ( 'sybgtjxt' ) or die ( 'could not select database' );
mysql_query ( "set names gbk" );

?>


實驗報告提交系統
h2, font { font-style: oblique; color: #FCC898; font-weight: normal id=top; valign =top; position: relative; } function YanZheng() { var cname = document.getElementById("cname").value; var tname = document.getElementById("tname").value; var ppro = document.getElementById("ppro").value; var pgrade = document.getElementById("pgrade").value; var pcol = document.getElementById("pcol").value; //var pcutdate = document.getElementById("pcutdate").value; var pname = document.getElementById("pname").value; var paim = document.form1.paim.value; var pcontent = document.getElementById("pcontent").value; var pstep = document.getElementById("pstep").value; var panalyse = document.getElementById("panalyse").value; var presult = document.getElementById(" presult").value; //這個功能沒實現 if (cname=="") { window.alert("請輸入所有內容"); return false; } } function Reset() { document.getElementById("cname").value = ""; document.getElementById("tname").value = 0; document.getElementById("ppro").value = 0; document.getElementById("pgrade").value = 0; document.getElementById("pcol").value = 0; document.getElementById("pcutdate").value = ""; document.getElementById("pname").value = ""; document.getElementById("paim").value = ""; document.getElementById("pcontent").value = ""; document.getElementById("pstep").value = ""; document.getElementById("panalyse").value = ""; document.getElementById("presult").value = ""; } function YYYYMMDDstart() { MonHead = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; //先給年下拉框賦內容 var y = new Date().getFullYear(); for (var i = (y-30); i < (y+30); i++) //以今年為准,前30年,後30年 document.form1.YYYY.options.add(new Option(" "+ i, i)); //賦月份的下拉框 for (var i = 1; i < 13; i++){ if(i>=1&&i<10) document.form1.MM.options.add(new Option(" " +"0"+i, i)); else{ document.form1.MM.options.add(new Option(" "+i, i)); } } document.form1.YYYY.value = y; document.form1.MM.value = new Date().getMonth() + 1; var n = MonHead[new Date().getMonth()]; if (new Date().getMonth() ==1 && IsPinYear(YYYYvalue)) n++; writeDay(n); //賦日期下拉框 document.form1.DD.value = new Date().getDate(); } if(document.attachEvent) window.attachEvent("onload", YYYYMMDDstart); else window.addEventListener('load', YYYYMMDDstart, false); function YYYYDD(str) //年發生變化時日期發生變化(主要是判斷閏平年) { var MMvalue = document.form1.MM.options[document.form1.MM.selectedIndex].value; if (MMvalue == ""){ var e = document.form1.DD; optionsClear(e); return;} var n = MonHead[MMvalue - 1]; if (MMvalue ==2 && IsPinYear(str)) n++; writeDay(n) } function MMDD(str) //月發生變化時日期聯動 { var YYYYvalue = document.form1.YYYY.options[document.form1.YYYY.selectedIndex].value; if (YYYYvalue == ""){ var e = document.form1.DD; optionsClear(e); return;} var n = MonHead[str - 1]; if (str ==2 && IsPinYear(YYYYvalue)) n++; writeDay(n) } function writeDay(n) //據條件寫日期的下拉框 { var e = document.form1.DD; optionsClear(e); for (var i=1; i<(n+1); i++) e.options.add(new Option(" "+ i, i)); } function IsPinYear(year)//判斷是否閏平年 { return(0 == year%4 && (year%100 !=0 || year%400 == 0)); } function optionsClear(e) { e.options.length = 1; }



onsubmit="return YanZheng();">
        <caption>
            <h2>布置作業</h2>
        </caption>
        <tr>
            <th style="text-align: left">課程名稱:</th>
            <td><input type="text" name="cname" id="cname"
                style="border-color: #FCC898; border-width: 3px; border-style: solid; font-weight: normal; width: 400px;">
            </td>
        </tr>

        <tr>
            <th style="text-align: left">任課老師:</th>
            <td><select name="tname" id="tname">
                    <option value='0' selected>請選擇</option>

<?php
$sql = "select tname from tblteacher";
$result = mysql_query ( $sql );
while ( $row = mysql_fetch_assoc ( $result ) ) {
?>

學    院:

請選擇
<?php
$sql = "select colname from college";
$result = mysql_query ( $sql );
while ( $row = mysql_fetch_assoc ( $result ) ) {
?>

專    業:

請選擇
<?php
$sql = "select pro_name from pro";
$result = mysql_query ( $sql );
while ( $row = mysql_fetch_assoc ( $result ) ) {
?>

年    級:

請選擇
<?php
$sql = "select sgrade from tblstudent";
$result = mysql_query ( $sql );
while ( $row = mysql_fetch_assoc ( $result ) ) {
?>

截止日期:







        <tr>
            <th style="text-align: left">實驗名稱:</th>
            <td><input type="text" name="pname" id="pname"
                style="border-color: #FCC898; border-width: 3px; border-style: solid; font-weight: normal; width: 400px;">
            </td>
        </tr>
        <tr>
            <th style="text-align: left">實驗目的:</th>
            <td><textarea cols="58" rows="4" name="paim" id="paim"
                    cellspacing="0"
                    style="border-color: #FCC898; resize: none; border-width: 3px; border-style: solid; font-weight: normal; width: 400px;"></textarea>
            </td>
        </tr>
        <tr>
            <th style="text-align: left">實驗內容:</th>
            <td><textarea cols="58" rows="4" name="pcontent" id="pcontent"
                    cellspacing="0"
                    style="border-color: #FCC898; resize: none; border-width: 3px; border-style: solid; font-weight: normal; width: 400px;"></textarea>
            </td>
        </tr>
        <tr>
            <th style="text-align: left">實驗步驟:</th>
            <td><textarea cols="58" rows="4" name="pstep" id="pstep"
                    cellspacing="0"
                    style="border-color: #FCC898; resize: none; border-width: 3px; border-style: solid; font-weight: normal; width: 400px;"></textarea>
            </td>
        </tr>
        <tr>
            <th style="text-align: left">實驗結果:</th>
            <td><textarea cols="58" rows="4" name="presult" id="presult"
                    cellspacing="0"
                    style="border-color: #FCC898; resize: none; border-width: 3px; border-style: solid; font-weight: normal; width: 400px;"></textarea>
            </td>
        </tr>
        <tr>
            <th style="text-align: left">分析討論:</th>
            <td><textarea cols="58" rows="4" name="panalyse" id="panalyse"
                    cellspacing="0"
                    style="border-color: #FCC898; resize: none; border-width: 3px; border-style: solid; font-weight: normal; width: 400px;""></textarea>
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center"><input type="submit" value="提交"> <input
                type="reset" value="重置" onclick="Reset()"></td>
        </tr>

    </table>
</form>


最佳回答:


js裡驗證非空2種方式 第一種判斷長度是不是大於0 即length>0
第二個 比對 =='' 或者 !=null

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved