English 中文(简体)
以超文本处理
原标题:Javascript problems with HTML form

我用java写法改变这种表格的出现,这样,当你点击每个无线电台时,“Body”投入的实地规模就会发生变化。 问题在于,只有在没有点击任何无线电信 but或我对其中一种投入进行“检查”时,它才会发挥作用。 该法典:

<form action= add_note  method="POST">
    Title <input type="text" name="title" /><br />

    Body 
    <div id="note_input">
        <textarea id="note_input1" name="body" cols="27" rows="5"></textarea>
    </div>


    Type

    <input type="radio" name="typey" value="text" onclick="text_input_type( text )" checked/>
    Text

    <input type="radio" name="typey" value="list" onclick="text_input_type( list )"/>
    List

    <input type="radio" name="typey" value="checklist" onclick="text_input_type( checklist )" />
    Checklist 

    <input type="submit" name="addnote" value="Add Note" />
</form>

<script type="text/javascript">
function text_input_type(type) {
    if (type== list ) {
        document.getElementById("note_input").innerHTML=
            "<input type="text" id="note_input1" name="body">";
    }
    if(type ==  checklist ) {
        document.getElementById("note_input").innerHTML=
            "<input type="text" id="note_input1" name="body">";
    }
    if (type ==  text ) {
        document.getElementById("note_input").innerHTML=
            "<textarea id="note_input1" name="body" cols="27" rows="5">
            </textarea>";
    }
}
</script>
问题回答

你的样本代码有错误,你就没有开始以下新行:

"<textarea id="note_input1" name="body" cols="27" rows="5">
</textarea>";

如果允许你使用 j。 它变得非常简单。 下面的《审判法》只是你想要使用“Qu”。

(使用外包人建议的开关案件)

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function(){ 
  $("input[type= radio ]").click(function(){      
    var type=$(this).attr( value );
    var target=$("#note_input");
    switch(type){
     case  list :
        target.html("<input type="text" id="note_input1" name="body">");
     break;  
     case  checklist :
        target.html("<input type="text" id="note_input1" name="body">");
     break;  
     case  text : 
     target.html("<textarea id="note_input1" name="body" cols="27" rows="5"></textarea>");
     break;
    };
  });
});
</script>
</head>
<body>
<form action= add_note  method="POST">
    Title <input type="text" name="title" /><br />
    Body 
    <div id="note_input">
        <textarea id="note_input1" name="body" cols="27" rows="5"></textarea>
    </div>
    Type
    <input type="radio" name="typey" value="text"/>
    Text
    <input type="radio" name="typey" value="list"/>
    List
    <input type="radio" name="typey" value="checklist"/>
    Checklist 
    <input type="submit" name="addnote" value="Add Note"/>
</form>
</body>
</html>




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签