<table align="center" width="100%" style="display:block "  border="1" cellspacing="0"  bordercolor="#000000">
   <tr>
   <td>素材id:<input type="text" size="50" id="material_id" name="material_id" value="<%=material_id %>"></td>
   </tr>
   <tr>
   <td>标题:<input type="text" size="50" id="title" name="title" value="<%=mp.getNAME() %>"></td>
   </tr>
<tr>
<td>类型:
    <select id="content_type" name="content_type">
    <option value="image">图片</option>
    <option value="ringtone">铃音</option>
    <option value="video">视频</option>
    <option value="audio">音乐</option>
    <option value="game">游戏</option>
     </select>
    </td>
   </tr>
   <tr>
   <td>image_url:<input type="text" size="50" id="image_url" name="image_url" value="http://218.206.70.172/<%=mp.getPREVFILE() %>"></td>
   </tr>
   <tr>
   <td>artist:<input type="text" size="50" id="artist" name="artist" value=""></td>
   </tr>
   <tr>
   <td>album:<input type="text" size="50" id="album" name="album" value=""></td>
   </tr>
   <tr>
   <td>description:<input type="text" size="50" id="description" name="description" value=""></td>
   </tr>
   <tr>
   <td>developer:<input type="text" size="50" id="developer" name="developer" value=""></td>
   </tr>
   <tr>
   <td>app_platform:<input type="text" size="50" id="app_platform" name="app_platform" value=""></td>
   </tr>
   <tr>
    <td>service_id:<input type="text" size="50" id="service_id" name="service_id" value=""></td>
   </tr>
    <tr>
    <td>price:<input type="text" size="50" id="price" name="price" value=""></td>
   </tr>
   <tr>
   <td><input type="submit" value="提交"></td>
   </tr>
   </table>
我有这个table,其中有个select选项,我想实现选择图片下面的输入框就给个提示,比如在<input>后面加个星号,告诉人哪项是必须填的,现在问题是我选图片下面的其中几项是必填的,当我选择音乐别的几项是必填的,我个js要怎么才能实现

解决方案 »

  1.   

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>test</title>
    <script>
    function sub(){
    var type = document.getElementById("content_type").value;
    if(type=="image"){
    if(document.getElementById("image_url").value==""){
    alert("image_url必填");
    }
    }else if(type=="ringtone"){
    if(document.getElementById("artist").value==""){
    alert("artist必填");
    }
    }
    //依次类推
    }</script>
    </head><body>
    <table align="center" width="100%" style="display:block "  border="1" cellspacing="0"  bordercolor="#000000">
           <tr>
           <td>素材id:<input type="text" size="50" id="material_id" name="material_id" value="<%=material_id %>"></td>
           </tr>
           <tr>
           <td>标题:<input type="text" size="50" id="title" name="title" value="<%=mp.getNAME() %>"></td>
           </tr>
        <tr>
        <td>类型:
            <select id="content_type" name="content_type">
                    <option value="image">图片</option>
                    <option value="ringtone">铃音</option>
                    <option value="video">视频</option>
                    <option value="audio">音乐</option>
                    <option value="game">游戏</option>
            </select>
        </td>
           </tr>
           <tr>
           <td>image_url:<input type="text" size="50" id="image_url" name="image_url" value="http://218.206.70.172/<%=mp.getPREVFILE() %>"></td>
           </tr>
           <tr>
           <td>artist:<input type="text" size="50" id="artist" name="artist" value=""></td>    
           </tr>
           <tr>
           <td>album:<input type="text" size="50" id="album" name="album" value=""></td>    
           </tr>
           <tr>
           <td>description:<input type="text" size="50" id="description" name="description" value=""></td>
           </tr>
           <tr>
           <td>developer:<input type="text" size="50" id="developer" name="developer" value=""></td>
           </tr>
           <tr>
           <td>app_platform:<input type="text" size="50" id="app_platform" name="app_platform" value=""></td>
           </tr>
           <tr>
            <td>service_id:<input type="text" size="50" id="service_id" name="service_id" value=""></td>
           </tr>
            <tr>
            <td>price:<input type="text" size="50" id="price" name="price" value=""></td>
           </tr>
           <tr>
           <td><input type="submit" value="提交" onclick="sub()"></td>
           </tr>
           </table>
    </body></html>
      

  2.   

    不好意思,没写全,本来期望LZ自己加上的
    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>test</title>
    <script>
    function sub(){
    var type = document.getElementById("content_type").value;
    if(type=="image"){
        if(document.getElementById("image_url").value==""){
            alert("image_url必填");
            document.getElementById("image_url").focus();
            return false;
        }
    }else if(type=="ringtone"){
        if(document.getElementById("artist").value==""){
            alert("artist必填");
            document.getElementById("artist").focus();
            return false;
        }
    }
    //依次类推
    }</script>
    </head><body>
    <form action="http://www.baidu.com" onSubmit="return sub();">
    <table align="center" width="100%" style="display:block "  border="1" cellspacing="0"  bordercolor="#000000">
           <tr>
           <td>素材id:<input type="text" size="50" id="material_id" name="material_id" value="<%=material_id %>"></td>
           </tr>
           <tr>
           <td>标题:<input type="text" size="50" id="title" name="title" value="<%=mp.getNAME() %>"></td>
           </tr>
        <tr>
        <td>类型:
            <select id="content_type" name="content_type">
                    <option value="image">图片</option>
                    <option value="ringtone">铃音</option>
                    <option value="video">视频</option>
                    <option value="audio">音乐</option>
                    <option value="game">游戏</option>
            </select>
        </td>
           </tr>
           <tr>
           <td>image_url:<input type="text" size="50" id="image_url" name="image_url" value="http://218.206.70.172/<%=mp.getPREVFILE() %>"></td>
           </tr>
           <tr>
           <td>artist:<input type="text" size="50" id="artist" name="artist" value=""></td>    
           </tr>
           <tr>
           <td>album:<input type="text" size="50" id="album" name="album" value=""></td>    
           </tr>
           <tr>
           <td>description:<input type="text" size="50" id="description" name="description" value=""></td>
           </tr>
           <tr>
           <td>developer:<input type="text" size="50" id="developer" name="developer" value=""></td>
           </tr>
           <tr>
           <td>app_platform:<input type="text" size="50" id="app_platform" name="app_platform" value=""></td>
           </tr>
           <tr>
            <td>service_id:<input type="text" size="50" id="service_id" name="service_id" value=""></td>
           </tr>
            <tr>
            <td>price:<input type="text" size="50" id="price" name="price" value=""></td>
           </tr>
           <tr>
           <td><input type="submit" value="提交"></td>
           </tr>
           </table>
    </form>
    </body></html>
      

  3.   

    谢谢啊,可惜我不是想要alert提示,我是想要他在<input type="text">后面加标注,告诉人我选的类型低下都哪几项是必填的,比如加个星号,就跟咱们注册东西似的
      

  4.   


    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>test</title>
    <script>
    function langchunlin(s){
      if (s=='audio'){
        var arrMustFill=Array("artist","album")//将必填的控件ID放入数组
        for(var i=0;i<arrMustFill.length;i++){
          document.getElementById(arrMustFill[i]).outerHTML+="<font color='#FF0000'>*必填</font>"
        }  }}</script>
    </head><body>
    <table align="center" width="100%" style="display:block "  border="1" cellspacing="0"  bordercolor="#000000">
           <tr>
           <td>素材id:<input type="text" size="50" id="material_id" name="material_id" value="<%=material_id %>"></td>
           </tr>
           <tr>
           <td>标题:<input type="text" size="50" id="title" name="title" value="<%=mp.getNAME() %>"></td>
           </tr>
        <tr>
        <td>类型:                                        <!--加下面的onchange-->
            <select id="content_type" name="content_type" onchange="javascript:langchunlin(this.value);">
                    <option value="image">图片</option>
                    <option value="ringtone">铃音</option>
                    <option value="video">视频</option>
                    <option value="audio">音乐</option>
                    <option value="game">游戏</option>
            </select>
        </td>
           </tr>
           <tr>
           <td>image_url:<input type="text" size="50" id="image_url" name="image_url" value="http://218.206.70.172/<%=mp.getPREVFILE() %>"></td>
           </tr>
           <tr>
           <td>artist:<input type="text" size="50" id="artist" name="artist" value=""></td>    
           </tr>
           <tr>
           <td>album:<input type="text" size="50" id="album" name="album" value=""></td>    
           </tr>
           <tr>
           <td>description:<input type="text" size="50" id="description" name="description" value=""></td>
           </tr>
           <tr>
           <td>developer:<input type="text" size="50" id="developer" name="developer" value=""></td>
           </tr>
           <tr>
           <td>app_platform:<input type="text" size="50" id="app_platform" name="app_platform" value=""></td>
           </tr>
           <tr>
            <td>service_id:<input type="text" size="50" id="service_id" name="service_id" value=""></td>
           </tr>
            <tr>
            <td>price:<input type="text" size="50" id="price" name="price" value=""></td>
           </tr>
           <tr>
           <td><input type="submit" value="提交" onclick="sub()"></td>
           </tr>
           </table>
    </body></html>