Ily*_*dev 0 forms jquery input
<input class="lf" id="r3-1" type="text"/>
<input class="rf" id="r4-1" type="text"/> <br>
<input class="lf" id="r3-2" type="text"/>
<input class="rf" id="r4-2" type="text"/> <br>
...
Run Code Online (Sandbox Code Playgroud)
如何从这个输入添加这样的值var code='';
?
ABC"值r3-1""值r4-1"
ABC"值r3-2""值r4-2"
请查看以下代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<title>Getting values ??from two different Inputs</title>
</head>
<body>
<div id="inputs">
<input class="lf" id="r3-1" type="text" value="2"/>
<input class="rf" id="r4-1" type="text" value="3"/> <br/>
<input class="lf" id="r3-2" type="text"/>
<input class="rf" id="r4-2" type="text"/> <br/>
<input class="lf" id="r3-3" type="text"/>
<input class="rf" id="r4-3" type="text"/> <br/>
<input class="lf" id="r3-4" type="text"/>
<input class="rf" id="r4-4" type="text"/> <br/>
</div>
<input id="submit" type="button" value="Test" />
<div id="OutPut">
</div>
<script type="text/javascript">
jQuery("#submit").click(function() {
var temp, output="";
jQuery('#inputs .lf').each(function(index) {
/*we can also use .rf or br
//jQuery('#inputs .rf').each(function(index) {
//jQuery('#inputs br').each(function(index) {
*/
temp = "ABC ";
jQuery('#inputs input[id$=-' + (index + 1) + ']').each(function() { temp += '"' + this.value + '" '; })
output += temp + "<br/>";
});
jQuery("#OutPut").html(output);
});
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
输出: -