0

我在这里有两个条件可以在更改功能上重置表格中的图像,但我希望将具有 browbandtable 类的图像重新设置为 browbandtable1 的不同图像。

这是表格,我有两页,一页有 browbandtable,这一页有 browbandtable1。我将如何对其进行编码,以便仅在类匹配时才使用该代码?

任何帮助将不胜感激

 <div id="black1">
    <table width="400" height="100" align="center" border="0" cellspacing="0" cellpadding="0">

      <tr>
    <th align="center" id="img1" scope="col"><img class="browbandtable1"src="images/none1.png" width='18' height='18'></th>
      <th align="center" id="img2" scope="col"><img class="browbandtable1"src="images/none1.png" width='18' height='18'></th>
      <th align="center" id="img3" scope="col" ><img class="browbandtable1"src="images/none1.png"width='18' height='18'></th>
      <th align="center" id="img4" scope="col" ><img class="browbandtable1"src="images/none1.png"width='18' height='18'></th>
      <th align="center" id="img5" scope="col"><img class="browbandtable1"src="images/none1.png" width='18' height='18'></th>
      <th align="center" id="img6"scope="col"><img class="browbandtable1"src="images/none1.png"  width='18' height='18'></th>
      <th align="center" id="img7"scope="col" ><img class="browbandtable1"src="images/none1.png" width='18' height='18'></th>
      <th align="center" id="img8"scope="col"><img class="browbandtable1"src="images/none1.png" width='18' height='18'></th>
      <th align="center" id="img9"scope="col"><img class="browbandtable1"src="images/none1.png" width='18' height='18'></th>
      <th align="center" id="img10"scope="col"><img class="browbandtable1"src="images/none1.png" width='18' height='18'></th>
      <th align="center" id="img11"scope="col"><img class="browbandtable1"src="images/none1.png" width='18' height='18'></th> 
      <th align="center" id="img12"scope="col"><img class="browbandtable1"src="images/none1.png" width='18' height='18'></th>
      <th align="center" id="img13"scope="col"><img class="browbandtable1"src="images/none1.png" width='18' height='18'></th>
      <th align="center" id="img14"scope="col"><img class="browbandtable1"src="images/none1.png" width='18' height='18'></th>
      <th align="center" id="img15"scope="col"><img class="browbandtable1"src="images/none1.png" width='18' height='18'></th>
               <th align="center" id="img16"scope="col"><img class="browbandtable1"src="images/none1.png" width='18' height='18'></th>
      <th align="center" id="img17"scope="col"><img class="browbandtable1"src="images/none1.png" width='18' height='18'></th>
      <th align="center" id="img18"scope="col"><img class="browbandtable1"src="images/none1.png" width='18' height='18'></th>        </tr>
</table></div>

//查询代码

$("[id^='img']").append('<img class="browbandtable" src="images/none.png" width="40" height="39">'); 
$("[id^='img']").append('<img class="browbandtable1" src="images/none1.png" width="18" height="18">');
4

1 回答 1

0

您想使用该.hasClass()方法。

if($("[id^='img']").hasClass("browbandtable1")){
    //Your Code here
}

编辑:起初我可能误解了,你可能想要做的是在你的选择器中选择你的元素,所以

$("[id^='img'].browbandtable").append('<img class="browbandtable" src="images/none.png" width="40" height="39">'); 
$("[id^='img.browbandtable1']").append('<img class="browbandtable1" src="images/none1.png" width="18" height="18">');

这将仅选择具有以 image 开头的 id 并且具有特定类名的元素。

于 2013-09-03T17:59:38.017 回答