使用 JQuery 将单选按钮标签替换为彩色 div
我使用单选按钮具有以下形式:
<div class="attributes">
<div class="attribute attribute-1 odd">
<div class="form-item">
<label>Color: <span class="form-required" title="This field is required.">*</span></label>
<div class="form-radios"><div class="form-item" id="edit-attributes-1-7-wrapper">
<label class="option" for="edit-attributes-1-7">
<input type="radio" id="edit-attributes-1-7" name="attributes[1]" value="7" class="form-radio" /> Black | 0x000000</label>
</div>
<div class="form-item" id="edit-attributes-1-6-wrapper">
<label class="option" for="edit-attributes-1-6">
<input type="radio" id="edit-attributes-1-6" name="attributes[1]" value="6" class="form-radio" /> Blue | 0x5E79A4</label>
</div>
<div class="form-item" id="edit-attributes-1-5-wrapper">
<label class="option" for="edit-attributes-1-5">
<input type="radio" id="edit-attributes-1-5" name="attributes[1]" value="5" class="form-radio" /> Red | 0xC33438</label>
</div>
</div>
</div>
我试图将“Color | 0xxxxxxx”部分替换为具有相关颜色的正方形。基本上,我需要读取“Color | 0xxxxxxx”,解析它以提取颜色的十六进制值,并将整个文本替换为像 有人对此有任何见解吗?
I have the following form using radio button:
<div class="attributes">
<div class="attribute attribute-1 odd">
<div class="form-item">
<label>Color: <span class="form-required" title="This field is required.">*</span></label>
<div class="form-radios"><div class="form-item" id="edit-attributes-1-7-wrapper">
<label class="option" for="edit-attributes-1-7">
<input type="radio" id="edit-attributes-1-7" name="attributes[1]" value="7" class="form-radio" /> Black | 0x000000</label>
</div>
<div class="form-item" id="edit-attributes-1-6-wrapper">
<label class="option" for="edit-attributes-1-6">
<input type="radio" id="edit-attributes-1-6" name="attributes[1]" value="6" class="form-radio" /> Blue | 0x5E79A4</label>
</div>
<div class="form-item" id="edit-attributes-1-5-wrapper">
<label class="option" for="edit-attributes-1-5">
<input type="radio" id="edit-attributes-1-5" name="attributes[1]" value="5" class="form-radio" /> Red | 0xC33438</label>
</div>
</div>
</div>
I am trying to replace the part "Color | 0xxxxxxx" with a square with the associated color. Basically, I need to read the "Color | 0xxxxxxx", parse it to extract the hex value of the color and replace the entire text with a div like <div style="height :20px;width:20px;background-color:0xxxxxx"></div>
Anybody has any insight on this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
首先,不要嵌套标签,而是将其放在输入旁边:
然后使用 jquery:
css:
First, instead of nesting the label, place it side with the input:
then use jquery:
css:
我终于找到了一种方法来永久删除文本并用跨度替换它,无需更改标记。
jsFiddle 演示。
I finally found a way to remove the text permanently and replace it with a span, no need to change the markup.
jsFiddle demo here.
以此:
希望这有帮助。干杯
With this:
Hope this helps. Cheers