首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >单击select选项,如何使用javascript显示隐藏字段?

单击select选项,如何使用javascript显示隐藏字段?
EN

Stack Overflow用户
提问于 2014-01-02 05:40:48
回答 2查看 678关注 0票数 0

我正在研究php如何显示隐藏字段?

我的数据库中有bp_scholarship_enq表,这个数据库我有职业字段,我想在我的数据库中添加新的职业,我是怎么做的?

代码语言:javascript
运行
复制
 <script>
    function showss(ids)
        {

            var  idss=ids;

            if(idss=="other")

            document.getElementById(idss).style.display='block';

        }   


</script>

<?php
echo "<select name='occupation' id='link_block' value='Source' style='width:196%'>
                      <option>select occupation </otpion>";
$sql = "SELECT * FROM bp_scholarship_enq";
$info = mysql_query($sql);

while ($row = mysql_fetch_array($info)) 
    echo "<option > '" . @$row["occupation"] . "'</option>";


echo '<option onClick="showss('.input_field.')">other</option>';
echo "</select>";
echo '<input type="hidden" name="other" id="input_field" />';
?>
EN

回答 2

Stack Overflow用户

发布于 2014-01-02 05:43:03

隐藏字段是不可见的。您可以使用文本框,并在css中将其可见性设置为false,并在更改select选项时使其可见。

代码语言:javascript
运行
复制
<input type="text" name="other" id="input_field" style="display:none"/>

    <select name='occupation' id='link_block' value='Source' style='width:196%' onChange="showText(this.selectedIndex);">
    ...............
    ...............
<option value="other">other</option>
    </select>

<script>
  function showtext(ind){
         var selectBox = document.getElementById('link_block');
         if(selectBox.options[ind].value=="other"){
                   document.getElementById('input_field').style.display = "block";
         }else{
                    document.getElementById('input_field').style.display = "none";
         }
  }
</script>
票数 1
EN

Stack Overflow用户

发布于 2014-01-02 05:49:18

而不是

代码语言:javascript
运行
复制
<input type="hidden" name="other" id="input_field" />

使:

代码语言:javascript
运行
复制
<input id="otherOccupation" class="hide" name="other" id="input_field" />

隐藏是一个设置可见性的类:隐藏;

然后,当用户选择"other“时,使用jquery删除该类。

代码语言:javascript
运行
复制
$("#otherOccupation").removeClass("hide")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20876991

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档