当我点击div然后输入1:last和input2:last必须得到其他值时,我有一些div和输入数组。你能救我吗?
<div class="super" onclick="changeValue(this)">60x90</div>
<div class="super" onclick="changeValue(this)">100x150</div>
<input name="input1[]" value="40"/>
<input name="input2[]" value="50"/>
function changeValue(o){
if($('div.super').text() == "60x90") {
$('input[name="input1[]"]').val('60');
$('input[name="input2[]"]').val('90');
}
}
答案 0 :(得分:1)
function changeValue($this)
{
console.log($($this).text())
if($($this).text() == "60x90")
{
$.each($($this).text().split('x'),function(key,value){
$('input[name="input'+(key+1)+'[]"]').val(value);
});
}
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="super" onclick="changeValue(this)">60x90</div>
<div class="super" onclick="changeValue(this)">100x150</div>
<input name='input1[]' value="40"/>
<input name='input2[]' value="50"/>
&#13;