如何在javascript中链接?

时间:2015-06-25 14:48:55

标签: javascript jquery hyperlink

如何在javascript中链接,我想将suggestion.full链接到#

JS:

var domains = ['hotmail.com', 'gmail.com', 'aol.com'];
var topLevelDomains = ["com", "net", "org"];

$('#email').on('blur', function(event) {
    console.log("event ", event);
    console.log("this ", $(this));
    $(this).mailcheck({
        domains: domains, // optional
        topLevelDomains: topLevelDomains, // optional
        suggested: function(element, suggestion) {
            // callback code
            console.log("suggestion ", suggestion.full);
            $('#suggestion').html("Did you mean? <b><i>" + suggestion.full + "</b></i>?");
        },
        empty: function(element) {
            // callback code
            $('#suggestion').html('No Suggestions :(');
        }
    });
});

HTML:

<label for="email">E-mailadres</label>
                            <input type="email" name="email" id="email" />
                            <p id="suggestion"></p>

我试过了:

$('#suggestion').html("Did you mean? <b><i>" + <a href="#">'suggestion.full</a>' + "</b></i>?");

提前致谢

1 个答案:

答案 0 :(得分:1)

您有一些报价位置和类型混淆。试试这个:

$('#suggestion').html('Did you mean? <b><i><a href="#">'+suggestion.full+'</a></b></i>?');

如果suggestion.full是网址,您可以将其添加到href中,如下所示:

$('#suggestion').html('Did you mean? <b><i><a href="'+suggestion.full+'">'+suggestion.full+'</a></b></i>?');