HTML 输入类型=“url” 表示 <a href =“”>效果

HTML Input Type="url" for <a href =""> Effects

本文关键字:效果 href 表示 输入 类型 url HTML      更新时间:2023-09-26

我需要以下格式 "<div><input type='url' id='link1' data-rowid='1' class='Link' value='here ...'/</div>" 对于 Jquery 进程。

但我想实现"<a href =''>here ...</a>"的外观。

有什么办法吗?

您可以尝试通过 CSS 以模仿常规 <a> 标签的方式设置输入样式:

#link1{
    display: inline-block;
    background: transparent;
    border: none;
    text-decoration: underline;
    // etc, etc...
}

这将保留原始<input>标签的功能,但具有链接的外观。

例如,你应该使用 ajax 来做到这一点

<div id="link" contenteditable="true"><a href="$link"><?php echo $link; ?></a></div>

JavaScript:

$(function () {
    var message_status = $("#status");
    $("div[contenteditable=true]").blur(function () {
        var projectid = $(this).attr("id");
        var text = $(this).text();
        $.post('update.php', linkid + "=" + text, function (data) {
            if (data != '') {
                message_status.fadeIn();
                message_status.text(data);
                setTimeout(function () {
                    message_status.fadeOut()
                }, 5000);
            }
        });
    });
});