Jquery编程 - src attr

时间:2014-09-04 04:43:27

标签: javascript jquery

面对更换“src”属性的问题。我是Jquery的新手。需要替换D:/Images/TaskList_1033_Button.pngD:/Images/TaskList_1033_Button_Disabled.png

<td>
    <div class=Editor>
        <span id=ctl02_G0_G22_G23_2_UserSelection_ECardButton_771_0_Editor class=Links disabled>
            <a style="FONT-FAMILY: Arial; COLOR: black; FONT-SIZE: xx-small" id=ctl02_G0_G22_G23_2_UserSelection_ECardButton_771_0_Editor_0 hotKey="0">
                <img src="D:/Images/TaskList_1033_Button.png">
                <span></span>
                <input id=ctl02_G0_G22_G23_2_UserSelection_ECardButton_771_0_Editor_Selected_0 value=false type=hidden name=ctl02$G0$G22$G23$2_UserSelection_ECardButton_771_0$Editor$Selected_0>
            </a>
        </span>
    </div>
</td>

我使用下面的代码进行替换,但它不起作用 脚本:

<div id="_vlv_script_">
    <script type="text/javascript">
        $(document).ready( function() {
            var vObj = '';
            $("span[id*= _UserSelection_ECardButton]").attr("Disabled", "Disabled"); 
            vObj = $("span[id*= _UserSelection_PriorityActionButton]").children("a");
            vObj.attr(img[src]).replace("src",src.replace(.png", "_Disabled.png")); 
            $("span[id*= _UserSelection_ECardButton]").attr("Disabled", "Disabled"); 
            vObj = $("span[id*= _UserSelection_ECardButton]").children("a");
            vObj.attr(img[src]).replace("src",src.replace(.png", "_Disabled.png")); 
        }); 
    </script>
</div>

你能帮帮我吗??提前谢谢

2 个答案:

答案 0 :(得分:0)

在审核您的代码后,我发现您需要进行以下更改。

您可以尝试这样:

var currentSrc = vObj.find('img').attr('src');
currentSrc = currentSrc.replace(".png", "_Disabled.png");
vObj.find('img').attr('src', 'currentSrc');

答案 1 :(得分:0)

你的代码有两个小问题

 vObj.attr(img[src]).replace("src",src.replace(.png", "_Disabled.png")); 

应替换为

 vObj.attr(img[src]).replace("src",src.replace(".png", "_Disabled.png")); 

vObj.attr(img[src]).replace("src",src.replace(.png", "_Disabled.png"));

应替换为

vObj.attr(img[src]).replace("src",src.replace(".png", "_Disabled.png"));

然后再次检查问题是否仍然存在