Link Fill Script in input form

2019-08-23 01:54发布

I have a script that fills in certain links when you click on them in an input form.

But i am having one issue.

For some reason i specified the links to call the class linkText and specified certain values to be displayed in the input text field when clicked.

But for some reason the whole link will show including the class and value.

So for example it will display <a class="linkInsert" value="This Value">HTML Link (websites / blogs)</a>

instead of the value which i want which is "This Value"

I just want the value to display but it displays the whole code.

You can see what i mean here jsFiddle

3条回答
贪生不怕死
2楼-- · 2019-08-23 02:27

You can also use just

$('a.linkInsert').click(
function(e){
 e.preventDefault();
 $('#linkText').val($(this).val());
});
查看更多
姐就是有狂的资本
3楼-- · 2019-08-23 02:32

You are placing the html of parent element into the text box.

Instead you should use the following code that injects the value of the linked that is clicked

$('a.linkInsert').click(
    function(e){
        e.preventDefault();
        $('#linkText').val($(this).attr("value"));
    });
查看更多
Emotional °昔
4楼-- · 2019-08-23 02:40

Change html() into text()

$('a.linkInsert').click(
    function(e){
        e.preventDefault();
        $('#linkText').val($(this).parent().text());
    });

or this one:

$('a.linkInsert').click(
    function(e){
        e.preventDefault();
        $('#linkText').val($(this).attr('value'));
    });

​
查看更多
登录 后发表回答