单击更改超链接图像

时间:2013-04-08 18:00:02

标签: javascript jquery html jquery-selectors

您好我正在尝试更改超链接的图像,如下所示。但是选择按钮的图像不会更改为loading.gif。我究竟做错了什么?我是jquery的新手。在期待中感谢

 <HTML><HEAD>
    <SCRIPT type=text/javascript src="jquery.js"></SCRIPT>
    </HEAD>
    <BODY>
    <TABLE>
    <TBODY>
    <TR>
    <TD><A id=webservice_submit href="javascript:document.frm_correction.submit()" jQuery1365443220846="2">
        <IMG onmouseover="MM_swapImage('Correction subj','','http://localhost:6868/corrmgr/img/select_up.gif',0)" onmouseout=MM_swapImgRestore() name="Correction Subj" alt="Correction Subj" src="http://localhost:6868/corrmgr/img/select.gif" oSrc="http://localhost:6868/corrmgr/img/select.gif"> 
         </A></TD></TD></TR></TBODY></TABLE>
    <DIV style="DISPLAY: none" id=loading jQuery1365443220846="3"><IMG name="Please wait..." alt="Please wait while the request is being processed..." src="http://localhost:6868/corrmgr/img/bert2.gif"> </DIV>
    <SCRIPT language=javascript>  
        var $loading = $('#loading'); 

        $('#webservice_submit').click(function(){     
            $loading.toggle();    
            if( $loading.is(':visible') ){
                alert("invoking web services");
                $('#image img').attr('src', 'http://localhost:63531/corrmgr/img/loading.gif');
                return ($(this).attr('disabled')) ? false : true;          
            }
        }); 

        $('#loading').hide(); 
    </SCRIPT>
    </BODY></HTML>

2 个答案:

答案 0 :(得分:3)

你的选择器不对。改变这个:

$('#image img')

到此:

$('#image')

<img>提供相应的id

<IMG id="image" ...>

答案 1 :(得分:0)

我认为你想将Loader Image分配给下面的图片标签

<IMG name="Please wait..." alt="Please wait while the request is being processed..." 
src="http://localhost:6868/corrmgr/img/bert2.gif">

如果我了解你......你改变你的代码如下......

FROM:

$('#image img').attr('src', 'http://localhost:63531/corrmgr/img/loading.gif');

TO:

$("img[name='Please wait...']").attr('src', 'http://localhost:63531/corrmgr/img/loading.gif');