1 回答
TA贡献1798条经验 获得超3个赞
你可以这样做:
$('#foo-list').change(function() {
var opt = $(this.options[this.selectedIndex]);
var url = opt.attr('data-url');
var model = $("input[name='model']").val().toLowerCase().replace(" ","-");
$('#url').html('<a href="https://www.apple.com/'+url+'shop/buy-iphone/' + model + '" target="_blank" >Apple product site</a>');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select class="paselect" id="foo-list">
<option data-country="Australia" data-iso="AUD" data-cur="A$" data-url="au/">Australia</option>
<option data-country="Austria" data-iso="EUR" data-cur="&euro;" data-url="at/">Austria</option>
<option data-country="Brazil" data-iso="BRL" data-cur="B$" data-url="br/">Brazil</option>
</select>
<input name='model' type="text" value="iPhone ">
<p>
<span id='url'></span><br>
</p>
添加回答
举报