1 回答
TA贡献2036条经验 获得超8个赞
提供您的 JS 元素 ID,然后更改text.value为text.textContent. 另外,请确保每次都替换文本,而不是添加文本(即text.textContent = 'Product Name: ' + ...):
var text = document.getElementById('name')
var drop = document.getElementById('dropdown')
drop.addEventListener('change', function(e) {
text.textContent = 'Product Name: ' + e.target.value
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="caption">
<h4 data-name="product_name" id="name">Product Name</h4>
<p data-name="product_desc">Yellow</p>
<hr class="line">
<div class="form-group">
<label>Size: </label>
<select id="dropdown" name="product_size" class="form-control input-sm">
<option>Iphone 11 6.1</option>
<option>IPhone 11 Pro 5.8</option>
<option>Iphone 11 Pro Max 6.5</option>
<option>Iphone X</option>
<option>Iphone XS</option>
<option>Iphone XS Max</option>
<option>Iphone XR</option>
<option>Iphone 7</option>
<option>Iphone 8</option>
<option>Iphone 7 Plus</option>
<option>Iphone 8 Plus</option>
<option>Iphone 6</option>
<option>Iphone 6s</option>
<option>Iphone 6 Plus</option>
<option>Iphone 6s Plus</option>
</select>
</div>
</div>
- 1 回答
- 0 关注
- 96 浏览
添加回答
举报