如何使用 jquery 添加文本到 span
我正在尝试将组合框的选定值添加到其前面的范围中。但失败太悲惨了。 我正在尝试使用以下代码:
<span></span><select multiple ="multiple" ondblclick="$(this).css('display','none').prev().css('display','inline').addClass('sss').html($(this).val());">....</select>
这里有什么错误?我怎样才能轻松做到呢?
我希望它在双击事件中触发。因为双击组合框的选项后,它应该消失,选定的文本应该出现在跨度中
,当然我忘记告诉我的选择框不是选择框。它是一个列表框。即多个=“多个”
I am trying to add the selected value of combo box to its preceding span. but it failed too sad.
I am trying with following code:
<span></span><select multiple ="multiple" ondblclick="$(this).css('display','none').prev().css('display','inline').addClass('sss').html($(this).val());">....</select>
What's the error here? how can i do it easily?
I want it to trigger in double click event. as after double clicking on option of combo box it should disappear and selected text should appear in span
and of course i forgot to tell that my select box is not selectbox. its a lisstbox. i.e multiple="multiple"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试类似:
JS Fiddle 演示。
参考文献:
change()
。prev()
。addClass()
。text()
。val()
。Try something like:
JS Fiddle demo.
References:
change()
.prev()
.addClass()
.text()
.val()
.您需要在
select
标记中放置一个option
。js
示例: http://jsfiddle.js网/jasongennaro/AKa9b/
编辑
根据评论not work in context of multiple option,我修改如下:
第二个示例: http://jsfiddle.net/jasongennaro/AKa9b/2/
You need to put an
option
in yourselect
tag.js
Example: http://jsfiddle.net/jasongennaro/AKa9b/
EDIT
Based on the comment not working in context of multiple option, I revised as follows:
Second example: http://jsfiddle.net/jasongennaro/AKa9b/2/