2014-09-04 50 views
-1

在更換「SRC」 attribute.I面對的問題是新來Jquery.Need由
D:/Images/TaskList_1033_Button_Disabled.pngjQuery的編程 - SRC ATTR

<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> 

更換D:/Images/TaskList_1033_Button.png我用下面的代碼進行更換,但它不工作 腳本:

<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> 

請你幫我嗎?..謝謝提前

+3

請格式化你的代碼.. – VPK 2014-09-04 04:43:52

回答

0

後檢查你的代碼我發現你需要做出以下改變。

你可以嘗試這樣的:

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

我想你已經錯把單引號src屬性的值。 – VPK 2014-09-04 04:53:26

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")); 

或更換然後再檢查問題仍然存在不