Home  >  Article  >  Web Front-end  >  The onchange event bound to the select tag in JQuery then pops up the selected value and implements jumps and parameter transfers.

The onchange event bound to the select tag in JQuery then pops up the selected value and implements jumps and parameter transfers.

黄舟
黄舟Original
2018-05-12 15:44:133856browse

The onchange event bound to the select tag in JQueryThen pop up the selected value and implement jump and parameter passing

<script src="jquery.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function(){  
$(&#39;#mySelect&#39;).change(function(){  
alert($(this).children(&#39;option:selected&#39;).val());  
var p1=$(this).children(&#39;option:selected&#39;).val();//这就是selected的值  
var p2=$(&#39;#param2&#39;).val();//获取本页面其他标签的值  
window.location.href="xx.php?param1="+p1+"¶m2="+p2+"";//页面跳转并传参  
})  
})  
</script>
<select id="mySelect">
<option value="1">one</option>
<option value="2" selected="selected">two</option>
<option value="3">three</option>
</select>
<input type="text" value="ooo" name="param2" id="param2"/>
  1. jquery Get the text and value selected by select

  2. Get the selected text of select:

$("#ddlregtype").find("option:selected").text();
  1. Get the value selected by select:

$("#ddlregtype ").val();

2. Get the index selected by select:

$("#ddlregtype ").get(0).selectedindex;

1. Get the value and text of the selected select, the html code is as follows:

  1. <select id="mySelect">
    <option value="1">one</option>
    <option value="2">two</option>
    <option value="3">three</option>
    </select>

You can use the following script code s to get the selected value and text

$("#mySelect").val(); //获取选中记录的value值
$("#mySelect option:selected").text(); //获取选中记录的text值

2. Use new Option("text","value ") method adds option option

var obj = document.getElementById("mySelect");  
obj.add(new Option("4","4"));

3, deleteall options option

var obj = document.getElementById("mySelect");  
obj.options.length = 0;

4, delete selected option option

var obj = document.getElementById("mySelect");  
var index = obj.selectedIndex;  
obj.options.remove(index);

5, Modify the selected option option

var obj = document.getElementById("mySelect");  
var index = obj.selectedIndex;  
obj.options[index] = new Option("three",3); //更改对应的值
obj.options[index].selected = true; //保持选中状态

6, delete select

var obj = document.getElementById("mySelect");  
obj.parentNode.removeChild(obj); //移除当前对象

7, select the selected response event

$("#mySelect").change(function(){  
//添加所需要执行的操作代码
})


The above is the detailed content of The onchange event bound to the select tag in JQuery then pops up the selected value and implements jumps and parameter transfers.. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn