Home > Web Front-end > JS Tutorial > 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.

黄舟
Release: 2018-05-12 15:44:13
Original
3901 people have browsed it

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"/>
Copy after login
  1. jquery Get the text and value selected by select

  2. Get the selected text of select:

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

$("#ddlregtype ").val();
Copy after login

2. Get the index selected by select:

$("#ddlregtype ").get(0).selectedindex;
Copy after login

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>
    Copy after login

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

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

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

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

3, deleteall options option

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

4, delete selected option option

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

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; //保持选中状态
Copy after login

6, delete select

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

7, select the selected response event

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


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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template