Link in input text field

前端 未结 8 860
余生分开走
余生分开走 2020-12-17 21:43

HI All,

I know this is bit strange question, but please suggest.

I want to create a link on website url content in input type\"text\" field not any other htm

相关标签:
8条回答
  • 2020-12-17 22:23

    I don't know if I get the question right. As I've understood you want to be able to type in a ...-tag into an input-field. No other tags should be allowed. You can achieve this by using PHP for example:

    <!-- HTML-Code -->
    <input type="text" name="link" />
    
    // PHP-Code
    $link = strip_tags($_POST['link'], 'a'); // Remove all other tags than the <a>-Tag...
    

    Is that what you mean?

    0 讨论(0)
  • 2020-12-17 22:28

    This is how I did it with JavaScript and JQuery. This wraps the entire text field in a hyperlink, so essentially the entire text field is click-able, which may not be the functionality you are looking for. It worked for my purposes though.

    The reason I didn't just use a $(nameTextField).click(function(){...}) structure is because the text field I'm using has the disabled attribute set, so click functions aren't fired. That's why I had to wrap the text field in a hyperlink.

        // Make person name a hyperlink to page in new tab
        var nameLink = "/exampleUrl/?initStudentId=$" + studentId;
        $("#studentNameLink").replaceWith($("#studentNameLink").html()); // Unwrap any previously wrapped text fields
        $(nameTextField).wrap("<a id='studentNameLink' target='_blank' href='" + nameLink + "'>"); // Wrap text field in anchor
        $(nameTextField).css('color', '#326699'); // Make text blue
        $(nameTextField).val(studentName); // Set text field value
    
    0 讨论(0)
提交回复
热议问题