English 中文(简体)
动态 javascamp/php 格式,通过无线电创建第二字段
原标题:dynamic javascript/php form with radios creating a second field

我这里有个牙牙牙牙牙牙问题 目前为止是我的密码

<form name="job_app">
    Source?<br/>
        <input type="radio" name="source" value="GAZ" id="GAZ" /> Stonoway Gazette <br/>
        <input type="radio" name="source" value="JCP" id="JCP" /> Job Center <br/>
        <input type="radio" name="source" value="WOM" id="WOM" /> Word of Mouth <br/><br/>

    <script language="text/JavaScript">
        if (document.job_app.source.GAZ.checked){
            document.write= Issue <br/><input type="text" name="issue" /><br/><br/> ;
        }
        else if (document.job_app.source.JCP.checked){
            document.write= Ref <br/><input type="text" name="ref" /><br/><br/> ;
        }
        //word of mouth has no additional input so there is no if statement for it
    </script>
</form>

我希望这样做能创建(或解密) 问题或文本框, 取决于选择哪个收听按钮而不创建多个文本框 。

我从未和Java合作过, 也从未使用过类似语言。

This is the working code as of 07:15 26/05/2012 as thanks to Amy McCrobie. It has undergone some edits since Amy s version (see below) i have moved all scripts above the form to make adding the next few fields easier, added a statement for word of mouth, omitted <head> as that is part of 指数.php and e.php 和 e.php 等离子体 while this is for 窗体.php, added a spacer and made the function name more specific.

指数.php

<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
    <head>
        <?php
            include  ./e.php 和 e.php 等离子体 ;
        ?>
    </head>
    <?php
        /*if(isset($_POST[ submit ])){
            include  ./submit.php ;
        }
        else{*/
            include  ./窗体.php ;
        //}
    ?>
</html>

e.php 和 e.php 等离子体

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
<meta http-Equiv="Cache-Control" Content="no-cache" />
<meta http-Equiv="Pragma" Content="no-cache" />
<meta http-Equiv="Expires" Content="0" />
<title>job_app</title>
<link rel="StyleSheet" type="text/css" href="./样式(cs)"/>

窗体.php

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $("#issueEl").hide();
    $("#refEl").hide();
});
    function showHide_source(){
        if (document.getElementById( GAZ ).checked)
        {
            document.getElementById( issueEl ).style.display =  block ;
            document.getElementById( refEl ).style.display =  none ;
            document.getElementById( src_spEl ).style.display =  none ;
        } 
        if (document.getElementById( JCP ).checked)
        {
            document.getElementById( issueEl ).style.display =  none ;
            document.getElementById( refEl ).style.display =  block ;
            document.getElementById( src_spEl ).style.display =  none ;
        }
    if (document.getElementById( WOM ).checked)
        {
            document.getElementById( issueEl ).style.display =  none ;
            document.getElementById( refEl ).style.display =  none ;
            document.getElementById( src_spEl ).style.display =  block ;
        }
    }
</script>
<form name="job_app" action="" method="post"> 
    Source?<br/> 
        <input type="radio" name="source" value="GAZ" id="GAZ" onChange="showHide_source()" /> Stonoway Gazette <br/> 
        <input type="radio" name="source" value="JCP" id="JCP" onChange="showHide_source()" /> Job Center <br/> 
        <input type="radio" name="source" value="WOM" id="WOM" onChange="showHide_source()" /> Word of Mouth <br/><br/> 
    <div class="hideable" id="issueEl">Issue <br/><input type="text" name="issue" /><br/><br/></div>
    <div class="hideable" id="refEl">Ref <br/><input type="text" name="ref" /><br/><br/></div>
    <div class="hideable" id="src_spEl"></div>
    rest of form        
    <input...
     .../>
</form>

样式(cs)

div.hideable{
    height: 62px;
}
最佳回答

尝试此 :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta http-Equiv="Cache-Control" Content="no-cache">
    <meta http-Equiv="Pragma" Content="no-cache">
    <meta http-Equiv="Expires" Content="0">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("#issueEl").hide();
            $("#refEl").hide();
        });
    </script>
    <title>Test</title>
</head>
<body>
<form name="job_app" action="" method="post"> 
    Source?<br/> 
        <input type="radio" name="source" value="GAZ" id="GAZ" onChange="showHide()" /> Stonoway Gazette <br/> 
        <input type="radio" name="source" value="JCP" id="JCP" onChange="showHide()" /> Job Center <br/> 
        <input type="radio" name="source" value="WOM" id="WOM" onChange="showHide()" /> Word of Mouth <br/><br/> 
        <div id="issueEl">Issue <br/><input type="text" name="issue" /><br/><br/></div>
        <div id="refEl">Issue <br/><input type="text" name="ref" /><br/><br/></div>
</form>
<script type="text/javascript">
function showHide(){
    if (document.getElementById( GAZ ).checked)
    {
        document.getElementById( issueEl ).style.display =  block ;
        document.getElementById( refEl ).style.display =  none ;
    } 
    if (document.getElementById( JCP ).checked)
    {
        document.getElementById( issueEl ).style.display =  none ;
        document.getElementById( refEl ).style.display =  block ;
    }
}
</script>
</body>
</html>
问题回答

I would suggest jQuery, it s not hard to learn, in fact I find it much easier than basic javascript also I would go the route of two textboxes that are hidden, and then showing them via jQuery

我想如果用户检查一个无线电按钮, 然后另外两个文本框就会出现

并添加jQuery (这很容易, 就像在您页面的顶部添加了脚本一样) 您的代码会更像这个...

<form name="job_app"> 
    Source?<br/> 
        <input id="GAZ" type="radio" name="source" value="GAZ" id="GAZ" /> Stonoway Gazette <br/> 
        <input id="JCP" type="radio" name="source" value="JCP" id="JCP" /> Job Center <br/> 
        <input id="WOM" type="radio" name="source" value="WOM" id="WOM" /> Word of Mouth <br/><br/> 
        Issue <br/><input id="issue" type="text" name="issue" /><br/><br/>
        Issue <br/><input id="ref" type="text" name="ref" /><br/><br/>

    <script language="text/JavaScript">

        $("#issue").css("display","none"); 
        $("#ref").css("display","none"); 

        if ($("#GAZ").checked){ 
            $("#issue").css("display","inline"); 
            $("#ref").css("display","none"); 

        } 
         if ($("#JCP").checked){ 
            $("#issue").css("display","none"); 
            $("#ref").css("display","inline"); 

        } 
        //word of mouth has no additional input so there is no if statement for it 
    </script> 
</form> 




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签