在文本框中合并两个选择标签值

时间:2018-07-28 23:08:17

标签: javascript html

我有两个选择标签和一个文本框。

<select name="select1">
   <option>1</option>
   <option>2</option>
</select>

<select name="select2">
   <option>1</option>
   <option>2</option>
</select>

<input type="number" name="text box">

我想在单击按钮时在文本框中显示两个选择标签(select1和select2)的值。提前致谢!

2 个答案:

答案 0 :(得分:0)

尝试一下

var combineBtn =  document.getElementById("combine");

combineBtn.addEventListener("click", function(){
    var select1 = document.getElementById("select1");
    var select2 = document.getElementById("select2");
    var valueSelect1 = select1.options[select1.selectedIndex].text;
    var valueSelect2 = select2.options[select2.selectedIndex].text;
    document.getElementById("text").value = valueSelect1 + valueSelect2;
});
<select id="select1" name="select1">
   <option>1</option>
   <option>2</option>
</select>

<select id="select2" name="select2">
   <option>1</option>
   <option>2</option>
</select>

<input type="number" id="text" name="text box">
<button id="combine">Combine</button>

答案 1 :(得分:0)

以防万一,您需要jQuery版本:)

my.regex = "([a-zA-Z]+)"

df %>% 
 mutate(name = str_to_title(name)) %>% 
 extract(name, 
         into = "last_name", 
         my.regex, 
         remove = FALSE) %>%  
left_join( lookup_table)

#> # A tibble: 4 x 4
#>   name                    last_name first_name middle_name
#>   <chr>                   <chr>     <chr>      <chr>      
#> 1 Clinton                 Clinton   Hillary    Rodham     
#> 2 Clinton, Hillary Rodham Clinton   Hillary    Rodham     
#> 3 Clinton, Hillary        Clinton   Hillary    Rodham     
#> 4 Clinton, Hil            Clinton   Hillary    Rodham