将 Jquery 用于 "select" 和 "option"?

Using Jquery for "select" and "option"?

首先感谢大家对我的帮助。抱歉我的英语不好:)

1.我需要jquery,可以把option选上显示在div.我需要在网站上取值加载。如果我选择另一个选项,它保持不变。

例如,我有:

<div class="example">
<select name="filter1" onchange="filtch1(this,'http://example.com/abc/19','0','1');">
<option value="0">Example</option>
<option value="1">Example 1</option>
<option value="2">Example 2</option>
<option value="3" selected>Example 3</option>
</select>
</div>

<div class="demo"></div>

结果:

<div class="example">
<select name="filter1" onchange="filtch1(this,'http://example.com/abc/19','0','1');">
<option value="0">Example</option>
<option value="1">Example 1</option>
<option value="2">Example 2</option>
<option value="3" selected>Example 3</option>
</select>
</div>

<div class="demo">Example 3</div>

2. 以及如何去除 option 的边缘。我尝试使用 css 但不能 !

感谢您的光临和帮助!

尝试将更改事件绑定到您的 select 元素,并在其中将其值分配给目标 div

$(".example select[name=filter1]").change(function(){
  $(this).closest(".example").next(".demo").text($(":selected", this).text());
  //If you want to access the selected value then just use this.value
});

DEMO

对于你的第二个问题,这个 question 可能会有所帮助。

select[name=filter1]change 事件中获取所选选项的文本并将其设置为 .demo

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="example">
    <select name="filter1">
        <option value="0">Example</option>
        <option value="1">Example 1</option>
        <option value="2">Example 2</option>
        <option value="3" selected>Example 3</option>
    </select>
</div>

<div class="demo">Selected Here</div>

<script>
    $('select[name=filter1]').change(function() {
        $('.demo').html($('option:selected', this).text());
    }).change(); //auto execute on page load
</script>

在更改功能的下拉菜单中执行此操作

还要为您的下拉列表添加一个 ID

$( "#id" ).change(function() {
      // add another id to your result div and then
('#divId').text(this.text());
}