各位大大您好,請問如何使用javascript來新增移除asp:imagebutton的imageurl,目前能在$('.ib').attr('src', '');
可以成功移除asp:imagebutton的圖片,但是無法新增回來,請問如何新增imagebutton的圖片,javascript如下:
<script>
$(document).ready(function () {
//如果瀏覽器放大縮小時
$(window).resize(function () {
if (window.matchMedia('only screen and (max-width: 1000px)').matches) {
//移除圖片
$('.ib').attr('src', '');
}
else {
//加入圖片
//無法成功
$('#ImageButton1').attr('src', 'MasterImages\BtLink01.png');
$('#ImageButton2').attr('src', 'MasterImages\BtLink02.png');
$('#ImageButton3').attr('src', 'MasterImages\BtLink03.png');
$('#ImageButton4').attr('src', 'MasterImages\BtLink04.png');
$('#ImageButton5').attr('src', 'MasterImages\BtLink05.png');
$('#ImageButton6').attr('src', 'MasterImages\BtLink06.png');
}})
//第一次開啟網站時
if(<%=(Not Page.isPostBack).ToString().ToLower() %>) chkMedia();
});
function chkMedia(){
if (window.matchMedia('only screen and (max-width: 1000px)').matches) {
//移除圖片
$('.ib').attr('src', '');
}
else {
//加入圖片
//無法成功
$('#ImageButton1').attr('src', 'MasterImages\BtLink01.png');
$('#ImageButton2').attr('src', 'MasterImages\BtLink02.png');
$('#ImageButton3').attr('src', 'MasterImages\BtLink03.png');
$('#ImageButton4').attr('src', 'MasterImages\BtLink04.png');
$('#ImageButton5').attr('src', 'MasterImages\BtLink05.png');
$('#ImageButton6').attr('src', 'MasterImages\BtLink06.png');
}; };
</script>
body如下:
</ul>
//imagebutton
<div id="LinkWebBt">
<asp:ImageButton class="ib" ID="ImageButton1" AlternateText="xxoo" runat="server" ImageUrl="MasterImages\BtLink01.png" PostBackUrl="http://www.taipei.gov.tw"></asp:ImageButton>
<asp:ImageButton class="ib" ID="ImageButton2" AlternateText="xxoo" runat="server" ImageUrl="MasterImages\BtLink02.png" PostBackUrl="http://www.cpami.gov.tw/chinese"></asp:ImageButton>
<asp:ImageButton class="ib" ID="ImageButton3" AlternateText="xxoo" runat="server" ImageUrl="MasterImages\BtLink03.png" PostBackUrl="http://www.pwb.taipei.gov.tw"></asp:ImageButton>
<asp:ImageButton class="ib" ID="ImageButton4" AlternateText="xxoo" runat="server" ImageUrl="MasterImages\BtLink04.png" PostBackUrl="http://web3.moeaboe.gov.tw"></asp:ImageButton>
<asp:ImageButton class="ib" ID="ImageButton5" AlternateText="xxoo" runat="server" ImageUrl="MasterImages\BtLink05.png" PostBackUrl="http://www.nco.taipei.gov.tw"></asp:ImageButton>
<asp:ImageButton class="ib" ID="ImageButton6" AlternateText="xxoo" runat="server" ImageUrl="MasterImages\BtLink06.png" PostBackUrl="http://www.pcc.gov.tw"></asp:ImageButton>
</div>
謝謝各位大大!
你如果有主版頁面,
id應該會跑掉,
可以試試
$('#<%=ImageButton1.ClientID %>').attr('src', 'MasterImages\BtLink01.png');