我无法理解脚本的问题以及为什么连第一个脚本alert
都不起作用?
http://jsfiddle.net/TULsL/17/
HTML:
<div id="listProducts">
<input type="radio" class="selectItem" name="inch" id="inch-1" value="1" />
<label for="inch-1">Имя: тостер, Цвет: серый, Тип: мелкая техника, Цена: <span class="priceIn">500</span>, Количество единиц на складе: 5</label>
<br/>
<input type="radio" class="selectItem" name="inch" id="inch-2" value="4" />
<label for="inch-2">Имя: миксер, Цвет: черный, Тип: мелкая техника, Цена: <span class="priceIn">300</span>, Количество единиц на складе: 3</label>
<br/>
<input type="radio" class="selectItem" name="inch" id="inch-3" value="5" />
<label for="inch-3">Имя: электрочайник, Цвет: белый, Тип: мелкая техника, Цена: <span class="priceIn">320</span>, Количество единиц на складе: 2</label>
<br/>
</div>
<input type="text" id="priceValue" />
JavaScript:
$(document).ready(function () {
$('#listProducts input:radio:checked']).click(function () {
alert('test');
var text = $(this).next('label').find('.priceIn').html();
alert(text);
$('#priceValue').text(text);
});
});
删除]和:checked,并且text(text)应该是val(text)
原版的:
$(document).ready(function () {
$('#listProducts input:radio:checked']).click(function () {
alert('test');
var text = $(this).next('label').find('.priceIn').html();
alert(text);
$('#priceValue').text(text);
});
});
正确的:
$(document).ready(function () {
$('#listProducts input:radio').click(function () {
alert('test');
var text = $(this).next('label').find('.priceIn').html();
alert(text);
$('#priceValue').val(text);
});
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句