Linkify custom link in function

后端 未结 1 615
有刺的猬
有刺的猬 2021-01-25 15:43

I am trying to create custom links based on different buttons using this html.




        
相关标签:
1条回答
  • 2021-01-25 16:35

    You have multiple div elements with id="linkified".

    id is unique; you cannot have more than one control with the same id.

    You could change your id attributes to class attributes and do something like this:


    HTML


    <input type="text" name="coachid" id="textbox1" value="22984" />
    <br />
    <br/>
    <button class="txtLinky" id="Mickey">Click Link</button>
    <br/>
    <div class="linkified">value</div>
    <br/>
    <button class="txtLinky" id="Donald">Click Link</button>
    <br/>
    <div class="linkified">value</div>
    

    JQUERY


    $(".txtLinky").on("click", function () 
    {
        var $this = $(this),
            id = $this.attr("id"),
            text = $("#textbox1").val();
        
        $this
            .nextAll('.linkified:first')
            .css({ padding: '10px' })
            .html
            (
                'http://www.example.com/'
                + id
                + '?referringRepId='
                + text
            )
            .linkify
            ({
                tagName: 'a',
                target: '_blank',
                newLine: '\n'
            });
    });
    

    See working jsFiddle demo

    0 讨论(0)
提交回复
热议问题