选定的下拉列表项在同一页面上显示文本

时间:2015-05-08 04:37:11

标签: javascript jquery html

您好我想在用户选择下拉列表项时显示文本。在页面上默认显示所有文本,但如果用户从下拉列表中选择一个项目,则只有焦点转到特定文本部分。在代码中如果我选择' a'项目然后页面焦点转到' a'项目文本。我不知道如何在javascript中执行此操作,任何人都可以帮助我。

<html>
<head>
<script type="text/javascript" language="javascript">
function ChangeText()
{
var parm = document.getElementById("mySelection");
document.getElementById('lbltxt').innerHTML = parm.options[parm.selectedIndex].text; 

}
</Script>
</head>
<body>
<select id="mySelection" onchange="Return ChangeText();" style="width:30%;">
<option disabled="disabled" selected="selected">Select method</option>
  <option value="1">a (new version)</option>
  <option value="2">b (old version)</option>
  <option value="3">c</option>
</select>

<b><label id="lblid" /></b><br /><br />
<strong id="1">A(For new versions)</strong><br />
In a, This can be done by denying the OPTIONS verb from the HTTP Verb Request Filtering rules in IIS.Following is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML content<br />

<img src="images/1.png" style="float:left;"><img style="float:left;" src="images/arrow_up.png" width="62" height="60">Following is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML content<br />
<br />
<strong id="2">b (For old versions)</strong><br />
  for B :<br />
Following is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML content
<img src="images/2.png">Following is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML content<br /><br />
<strong id="3">C</strong><br />
<p style="text-align:justify; font-size:17px;">Following is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML content</p>
</body>
</html>

4 个答案:

答案 0 :(得分:1)

首先你应该调用一个javascript函数在Dropdown的OnChange()事件中 然后,您可以在所需文本的位置添加标签。 您可以为标签设置页面加载(所有项目)的文本。 然后,在javascript中(当下拉列表更改时调用), 您可以根据下拉选项更改标签文本。

在页面加载中,您可以根据需要分配标签的值。

&#13;
&#13;
            		function ChangeText()
                        {
                          var contentText;
                          var selectedITem='';
                        var parm = document.getElementById("mySelection");
                          selectedITem =parm.options[parm.selectedIndex].text;
                          if(selectedITem == 'a')
                            contentText = 'Type What you want for option A'
                         else  if(selectedITem == 'b')
                            contentText = 'Type What you want for option B'
                          
                          
    str='<tr> <td>'  +  contentText +' </td> </tr>';
     $("#test").append(str);
                          

                        }
&#13;
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
        <table id="test">
              
              <tr>
              
            <td width="40%" align="left">
                                                
             <select id="mySelection" onchange="ChangeText();" style="width: 100%;">
               
             <option disabled="disabled"   selected="selected">Select method</option>
                  <option value="1">a</option>
                  <option value="2">b</option>
                  <option value="3">c</option>
                   </select>
                  &nbsp;&nbsp;&nbsp;
              </td>


              </tr>
              
              </table>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您应该在js中编写以下代码,希望它能正常工作。

$("#mySelection").on('change', function() {
  id = $(this).val();
  window.location.hash = "#"+id;
})

答案 2 :(得分:0)

HTML

public static void doStuffOnList(List<MyObject> myObjs) {
    myObjs.stream()
            .flatMap(o -> completedFuture(o)
                    .thenAccept(ABC::doStuff)
                    .handle((x, ex) -> ex != null ? Stream.of(ex) : null)
                    .join()
            ).reduce((ex1, ex2) -> {
                ex1.addSuppressed(ex2);
                return ex1;
            }).ifPresent(ex -> {
                throw new RuntimeException(ex);
            });
}

CSS

<select id="mySelection" style="width:30%;">
    <option disabled="disabled" selected>Select method</option>
    <option value="1">a (new version)</option>
    <option value="2">b (old version)</option>
    <option value="3">c</option>
</select><br /><br />

<table>
    <tr id="1" class="user">
        <td class="img">
            <img src="images/1.png" width="62" height="60"></td>
        <td class="description">
            <p><strong>A(For new versions)</strong></p>
            <p>In a, This can be done by denying the OPTIONS verb from the HTTP Verb Request Filtering rules in IIS.</p>
        </td>
    </tr>
    <tr id="2" class="user">
        <td class="img">
            <img src="images/arrow_up.png" width="62" height="60">
        </td>
        <td class="description">
            <p><strong>b (For old versions)</strong></p>
            <p>for B :<br />Following is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML content</p>
        </td>
    </tr>
    <tr id="3" class="user">
        <td class="img">
            <img src="images/2.png" width="62" height="60">
        </td>
        <td class="description">
            <p><strong>C</strong></p>
            <p>Following is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML contentFollowing is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML content</p>
        </td>
    </tr>
</table>

脚本

    table{
        margin: 20px;
    }
    table td{
        padding-left: 10px;
        padding-bottom: 10px;
        vertical-align: top;
    }
    .user{
        display: none;
    }

答案 3 :(得分:0)

您的代码很好,如果我理解您要做的事情,只需更正您的&#34; onchange&#34;打电话,我没有看到id =&#34; lbltxt&#34;所以我添加了一个: 更改代码的这一部分:

2, 1, 0, 0, 1
2, 1, 0, 1, 1
2, 1, 2, 0, 1
2, 1, 1, 1, 1
2, 1, 3, 0, 1
2, 1, 3, 1, 1

如果你还想要&#34;滚动&#34;你应该像这样修改你的js函数:

<body>
    <select id="mySelection" onchange="ChangeText();" style="width:30%;">
        <option disabled="disabled" selected="selected">Select method</option>
        <option value="1">a (new version)</option>
        <option value="2">b (old version)</option>
        <option value="3">c</option>
    </select>

    <b><label id="lblid" /></b><br /><br />
    //added element
    <div id="lbltxt" ></div><br /><br /> 
    .....