js/jqueryでselectをクリックしてピクチャパスを変更
411 ワード
これは非常に簡単な機能であり、実装の方法も多い.ここでは主にjsとjqueryを通じた実装コードについて説明する.
jsコード:
jqueryコード:
jsコード:
var img=document.getElementById('test-img')
var sel=document.getElementById('sel')
sel.addEventListener('change',function(){
img.src=this.value;
})
jqueryコード:
$('#sel').change(function(){
$('#test-img').attr('src',$(this).val());
})