我想用图像替换我的单选按钮,这是我的 html 将由系统生成,
<ul>
<li><input type="radio" name="id" value="68135112" title="Default / Default Title / Small" class="button-replace-size"/></li>
<li><input type="radio" name="id" value="70365102" title="Default / Default Title / Medium" class="button-replace-size"/></li>
<li><input type="radio" name="id" value="70365152" title="Default / Default Title / Large" class="button-replace-size"/></li>
<li><input type="radio" name="id" value="70365162" title="Default / Default Title / Extra Large" class="button-replace-size"/></li>
</ul>
我希望 jquery 脚本检查单选输入中的标题文本是否包含某些关键字或字母,然后相应地替换该单选按钮。
例如,如果发现单选按钮包含关键字 - 'Small',或'small',甚至's',则将此按钮替换为此<a>
标签,该标签将在css中设置为图像,
<a href="#" id="button-s" class="button-size hide-text" title="Click this to select size Small">S</a>
如果找到关键字 - 'Medium' 或 'medium' 这将是相同的情况......
这是我被困在的jquery,
if ($(':contains("Small")',$this_title).length > 0)
下面是我到目前为止出来的脚本......
this.replace_element_radio_size = function(){
/* radio button replacement - loop through each element */
$(".button-replace-size").each(function(){
if($(this).length > 0)
{
$(this).hide();
var $this = $(this);
var $this_title = $this.attr('title');
if ($(':contains("Small")',$this_title).length > 0)
{
$(this).after('<a href="#" id="button-s" class="button-size hide-text" title="Click this to select size Small">S</a>');
}
}
}
}
请给我一些想法来使它...谢谢。