用js隐藏选择文本
我有一个如下所示的选择选项。这些值是动态创建的。有没有办法使用js/jquery隐藏价格?
请记住,我无法访问文本,因此我无法将价格包含在跨度中并设置显示:无
<label for="input_1_33">Condition</label>
<select tabindex="2" name="input_33">
<option value="Please Select|" price="">Please Select</option>
<option value="Poor|-5" price="-£ 5.00">Poor -£ 5.00</option>
<option value="Average|0" price="">Average</option>
<option value="Good|5" price="+£ 5.00">Good +£ 5.00</option>
<option value="Excellent|10" price="+£ 10.00">Excellent +£ 10.00</option>
</select>
所以它看起来像这样:
<label for="input_1_33">Condition</label>
<select tabindex="2" name="input_33">
<option value="Please Select|" price="">Please Select</option>
<option value="Poor|-5" price="-£ 5.00">Poor</option>
<option value="Average|0" price="">Average</option>
<option value="Good|5" price="+£ 5.00">Good</option>
<option value="Excellent|10" price="+£ 10.00">Excellent</option>
</select>
提前致谢
I have a select option like below. The values are created dynamically. Is there a way to hide the prices using js/jquery?
Keep in mind i can't access the text, so i can't wrap price in a span and set display:none
<label for="input_1_33">Condition</label>
<select tabindex="2" name="input_33">
<option value="Please Select|" price="">Please Select</option>
<option value="Poor|-5" price="-£ 5.00">Poor -£ 5.00</option>
<option value="Average|0" price="">Average</option>
<option value="Good|5" price="+£ 5.00">Good +£ 5.00</option>
<option value="Excellent|10" price="+£ 10.00">Excellent +£ 10.00</option>
</select>
So it looks like this:
<label for="input_1_33">Condition</label>
<select tabindex="2" name="input_33">
<option value="Please Select|" price="">Please Select</option>
<option value="Poor|-5" price="-£ 5.00">Poor</option>
<option value="Average|0" price="">Average</option>
<option value="Good|5" price="+£ 5.00">Good</option>
<option value="Excellent|10" price="+£ 10.00">Excellent</option>
</select>
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一种超简洁的方法来完成您需要的操作: jsFiddle
jQuery:
Here's an ultra-concise way to do what you need: jsFiddle
jQuery:
为 Select 分配一个 ID,然后在脚本块中分配以下内容:
编辑:如您所见,我所做的就是在每个选项项中找到空格,然后在找到空格的地方剪切字符串。它会让“请选择”变成“请”,但你明白了。
祝你好运!
Assign an ID to the Select and then the following in a Script block:
EDIT: As you can see what I do is to find the space in each option item, and then cut the string where it find the space. It will make "Please Select" read "Please" but you get the drift.
Good luck!