亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Sistem siaran berita pembangunan PHP menerbitkan halaman HTML

new.jpg


Gambar di atas ialah halaman keluaran berita yang ingin kami lakukan

Borang <borang> serta latar belakang CSS ringkas

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>PHP中文網(wǎng)</title>
   
    <style>
        body{
            background-color: rgba(128, 128, 128, 0.3);
        }
    </style>
    
</head>
<body>
<form  method="post" action="new_post.php" name="myform">
    <h1>發(fā)布新聞系統(tǒng)</h1>
    <p>標(biāo)題:<input type="text" name="title"/></p>
    <p>內(nèi)容:<textarea cols=30 rows=5 name="content"></textarea></p>
    <p><button>發(fā)布新聞</button></p>
</form>
</body>
</html>

Kami perlu melakukan beberapa pengesahan pada halaman keluaran berita kami Jika tajuk dan kandungan berita tidak diisi, ia tidak dibenarkan untuk diterbitkan Kami menggunakan JS untuk melakukan pengesahan

Anda perlu buat pengesahan dalam acara <form> JS, kodnya adalah seperti berikut

<form method="post" action="new_post.php" onsubmit=" return foo();" name="myform">

Tambahkan kod berikut pada kepala

<script>
function foo(){
if(myform .title.value==""){
alert('Sila isikan tajuk berita anda');
myform.title.focus();
return false;
}
jika (myform.content.value==""){
alert('Kandungan berita tidak boleh kosong');
myform.content.focus();
return false;
}
}
</script>

Sekarang jika anda menghantar berita tanpa mengisi tajuk dan kandungan, ia tidak dibenarkan untuk diterbitkan


Kod lengkap fail new.html adalah seperti berikut

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>PHP中文網(wǎng)</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="format-detection" content="telephone=no" />
    <style>
        body{
            background-color: rgba(128, 128, 128, 0.3);
        }
    </style>
    <script>
        function foo(){
            if(myform.title.value==""){
                alert('請(qǐng)?zhí)顚懩愕男侣剺?biāo)題');
                myform.title.focus();
                return false;
            }
            if(myform.content.value==""){
                alert('新聞內(nèi)容不能為空哦');
                myform.content.focus();
                return false;
            }
        }
    </script>
</head>
<body>
<form  method="post" action="new_post.php" onsubmit=" return foo();" name="myform">
    <h1>發(fā)布新聞系統(tǒng)</h1>
    <p>標(biāo)題:<input type="text" name="title"/></p>
    <p>內(nèi)容:<textarea cols=30 rows=5 name="content"></textarea></p>
    <p><button>發(fā)布新聞</button></p>
</form>
</body>
</html>

Langkah seterusnya ialah menyerahkan maklumat berita yang kami isi pada halaman ke halaman new_post.php untuk diproses


Meneruskan pembelajaran
||
<!doctype html> <html> <head> <meta charset="utf-8"> <title>PHP中文網(wǎng)</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="format-detection" content="telephone=no" /> <style> body{ background-color: rgba(128, 128, 128, 0.3); } </style> <script> function foo(){ if(myform.title.value==""){ alert('請(qǐng)?zhí)顚懩愕男侣剺?biāo)題'); myform.title.focus(); return false; } if(myform.content.value==""){ alert('新聞內(nèi)容不能為空哦'); myform.content.focus(); return false; } } </script> </head> <body> <form method="post" action="new_post.php" onsubmit=" return foo();" name="myform"> <h1>發(fā)布新聞系統(tǒng)</h1> <p>標(biāo)題:<input type="text" name="title"/></p> <p>內(nèi)容:<textarea cols=30 rows=5 name="content"></textarea></p> <p><button>發(fā)布新聞</button></p> </form> </body> </html>