簡體   English   中英

jQuery:將輸出的文本換行嗎?

[英]jQuery: Wrap outputted text in span?

我有一個jQuery腳本,在輸出的文本后插入<input> 我的問題是在調用<input>之前如何將輸出的文本包裝在<span>

$(".todo-deadline").each(function() {
    $(this).html($(this).text() + "<input readonly='readonly' class='hasDatepicke2' type='text' value='"+$(this).text()+"' />");
});

嘗試

$(".todo-deadline").each(function() {
    var $this = $(this), text = $this.text();
    $this.empty().append($('<span />', {
        text: text
    })).append('<input readonly="readonly" class="hasDatepicke2" type="text" value="' + text + '" />')
});

演示: 小提琴

要么

$(".todo-deadline").html(function(idx, html) {
    return '<span>' + html + '</span>' + '<input readonly="readonly" class="hasDatepicke2" type="text" value="' + html + '" />'
});

演示: 小提琴

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM