Write a project today encountered a two-level linkage, during the encounter points, write a blog record.
Background controller:
@RequestMapping ("/faulttype")
@ResponseBody
Public map<string,object> faulttype (int id,httpservletrequest request) throws IOException
{
String returnmessage = "";
Get all child class failure types
List<faulttype> Faulist=faulttypeservice.getbyid (ID);
if (Faulist.size () >0) {
Request.setattribute ("Childtype", faulist);
ReturnMessage = "OK";
}else {
ReturnMessage = "no information found";
}
//*************************************************************
map<string,object> Returnmap = new hashmap<string,object> ();
Returnmap.put ("Childtype", faulist);
return returnmap;
}
————————————————————————————————————————————————————————————
Front-desk JSP:
<div class= "Col-sm-3" >
<div class= "Form-group" >
<label class= "col-3 control-label no-padding-right" >
Fault type: </label>
<select name= "Faulttype" id= "Faulttype" onchange= "Javascript:typechange ()" >
<c:foreach items= "${faultlist}" var= "Faulist" >
<option value= "${faulist.faultid}" >${faulist.faultcontent}</option>
</c:forEach>
</select>
</div>
</div>
<div class= "Col-sm-3" >
<div class= "Form-group" >
<label class= "col-3 control-label no-padding-right" >
Fault: </label>
<input id= "Childtypecont" name= "Childtypecont"
Value= "" type= "hidden" class= "col-sm-4 Form-control" placeholder= "Fault" >
<select name= "Faulttype1" id= "Faulttype1" ">
<option>--Please select--</option>
<c:foreach items= "${childtype}" var= "Faulist" >
<option value= "${faulist.faultid}" >${faulist.faultcontent}</option>
</c:forEach>
</select>
</select>
</div>
</div>
Js:
function Typechange () {
var type=$ ("#faulttype"). Val ();
var html = "<option>--Please select--</option>";
var commiturl = "faulttype.do?id=" + type;
$.ajax ({
Type: "POST",
ContentType: "Application/json",
Url:commiturl,
DataType: ' JSON ',
Success:function (Result) {
var curedata = $.extend (true, [], result);
if (curedata.childtype! = null) {
for (Var i=0;i<curedata.childtype.length;i++) {
html+= "<option value= '" +curedata.childtype[i].faultid+ ">" +curedata.childtype[i].faultcontent+ "</ Option> ";
}
$ ("#faulttype1"). empty ();
$ (HTML). AppendTo ("#faulttype1");
} }
});
}
——————————————————————————————————————————————————————————————————————————
The following is written by someone else (original address: http://blog.csdn.net/gis__/article/details/6647464)
——————————————————————————————————————————————————————————————————————————
A bad memory can be collected:
1, drop-down box:
var cc1 = $ (". formcselect[@name=' country '] option[@selected]"). text ();//Get a drop-down menu of selected items (note that there are spaces in the middle)
var cc2 = $ ('. formcselect[@name="Country"]). Val (); Get the value of the selected item in the drop-down menu
var cc3 = $ ('. FORMC select[@name="country"] '). attr ("id");//The ID property value of the selected item that gets the drop-down menu
$ ("#select"). empty ();//Empty the drop-down box//$ ("#select"). HTML (");
$ ("<optionvalueoptionvalue=' 1 '>1111</option>"). AppendTo ("#select") option to add a drop-down box
A little explanation:
1.select[@name=' country '] option[@selected] means having the Name property,
and the option element with the selected attribute in the Select element with the attribute value of ' country ';
You can see that there is an @ at the beginning of the property is followed by.
2, Radio Box:
$ ("input[@type=radio][@checked]"). Val (); Get the value of the selected item in the Radio box (note that there are no spaces in the middle)
$ ("input[@type=radio][@value=2]"). attr ("Checked", ' checked ');//Set Radio box value=2 is selected. ( Note There are no spaces in the middle)
3, check box:
$ ("input[@type=checkbox][@checked]"). Val ();//Gets the value of the check box for the first item selected
$ ("input[@type=checkbox][@checked]"). each (function () {////Because the check box is generally selected as multiple, you can loop the output
Alert (This). Val ());
});
$ ("#chk1"). attr ("Checked", "");//Not ticked
$ ("#chk2"). attr ("Checked", true);//tick
if ($ ("#chk1"). attr (' checked ') ==undefined) {}//Determine if a tick has been made
Of course the jquery selector is powerful. There are many other ways.
<script src= "jquery-1.2.1.js"type= "Text/javascript"></script>
<script language= "javascript"type= "Text/javascript">
$ (document). Ready (function () {
$ ("#selectTest"). Change (function ()
{
Alert ("Hello");
Alert ($ ("#selectTest"). attr ("name"));
$ ("a"). attr ("href", "xx.html");
window.location.href="xx.html";
Alert ($ ("#selectTest"). Val ());
Alert ($ ("#selectTest option[@selected]"). text ());
$ ("#selectTest"). attr ("Value", "2");
});
});
</Script>
<ahrefahref="#">aaass</a>
<!-- drop-down box--
- <select id= "selecttest"name= "Selecttest">
- <optionvalueoptionvalue="1">11</option>
- <optionvalueoptionvalue="2">22</option>
- <optionvalueoptionvalue="3">33</option>
- <optionvalueoptionvalue="4">44</option>
- <optionvalueoptionvalue="5">55</option>
- <optionvalueoptionvalue="6">66</option>
- </Select>
- Jqueryradio value, checkbox value, select Value, Radio selected, CheckBox selected, select selected, and its related gets the value of a set of radio selected items
- var item = $ (' input[@name=items][@checked] '). Val ();
- Gets the text of the Select selected item
- var item = $ ("select[@name=items] option[@selected]"). Text ();
- The second element of the Select drop-down box is the currently selected value
- $ (' #select_id ') [0]. SelectedIndex = 1;
- Radio the second element of a radio group is the currently selected value
- $ (' input[@name=items] '). Get (1). checked = true;
- Get Value:
- text box, text area: $ ("#txt"). attr ("value");
- Multi Box checkbox:$ ("#checkbox_id"). attr ("value");
- Radio Group Radio: $ ("input[@type=radio][@checked]"). Val ();
- Drop-down box select: $ (' #sel '). Val ();
- Control form elements:
- text box, text area: $ ("#txt"). attr ("Value", "");//Clear Contents
- $ ("#txt"). attr ("value", ' 11 ');//fill content
- Multiple marquee checkbox: $ ("#chk1"). attr ("Checked", "");//No Tick
- $ ("#chk2"). attr ("Checked", true);//tick
- if ($ ("#chk1"). attr (' checked ') ==undefined)//Determine if a tick has been made
- Radio Group radio:$ ("input[@type=Radio]"). attr ("Checked", ' 2 ');//Set value=2 for the currently selected Item
- drop-down box select:$ ("#sel"). attr ("value", '-sel3 ');//Set the VALUE=-SEL3 item as the current selection
- $ ("<optionvalueoptionvalue=' 1 '>1111</option>< OptionValueoptionvalue=' 2 '>2222</option> "). AppendTo (" #sel ")// option to add a drop-down box
- $ ("#sel"). empty ();//Empty drop-down box
- Gets the value of a set of radio selected items
- var item = $ (' input[@name=items][@checked] '). Val ();
- Gets the text of the Select selected item
- var item = $ ("select[@name=items] option[@selected]"). Text ();
- The second element of the Select drop-down box is the currently selected value
- $ (' #select_id ') [0]. SelectedIndex = 1;
- Radio the second element of a radio group is the currently selected value
- $ (' input[@name=items] '). Get (1). checked = true;
- Get Value:
- text box, text area: $ ("#txt"). attr ("value");
- Multi Box checkbox:$ ("#checkbox_id"). attr ("value");
- Radio Group Radio: $ ("input[@type=radio][@checked]"). Val ();
- Drop-down box select: $ (' #sel '). Val ();
- Control form elements:
- text box, text area: $ ("#txt"). attr ("Value", "");//Clear Contents
- $ ("#txt"). attr ("value", ' 11 ');//fill content
- Multiple marquee checkbox: $ ("#chk1"). attr ("Checked", "");//No Tick
- $ ("#chk2"). attr ("Checked", true);//tick
- if ($ ("#chk1"). attr (' checked ') ==undefined)//Determine if a tick has been made
- Radio Group radio:$ ("input[@type=Radio]"). attr ("Checked", ' 2 ');//Set value=2 for the currently selected Item
- drop-down box select:$ ("#sel"). attr ("value", '-sel3 ');//Set the VALUE=-SEL3 item as the current selection
- $ ("<optionvalueoptionvalue=' 1 '>1111</option>< OptionValueoptionvalue=' 2 '>2222</option> "). AppendTo (" #sel ")// option to add a drop-down box
- $ ("#sel"). empty ();//Empty drop-down box
Ajax in Spring MVC achieves level two linkage